FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
rmdec.c
Go to the documentation of this file.
1 /*
2  * "Real" compatible demuxer.
3  * Copyright (c) 2000, 2001 Fabrice Bellard
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * FFmpeg is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <inttypes.h>
23 
24 #include "libavutil/avassert.h"
25 #include "libavutil/avstring.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/dict.h"
30 #include "avformat.h"
31 #include "avio_internal.h"
32 #include "internal.h"
33 #include "rmsipr.h"
34 #include "rm.h"
35 
36 #define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for Cooker/ATRAC
37 #define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed
38 #define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8
39 #define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro
40 #define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC
41 #define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC
42 
43 struct RMStream {
44  AVPacket pkt; ///< place to store merged video frame / reordered audio data
45  int videobufsize; ///< current assembled frame size
46  int videobufpos; ///< position for the next slice in the video buffer
47  int curpic_num; ///< picture number of current frame
49  int64_t pktpos; ///< first slice position in file
50  /// Audio descrambling matrix parameters
51  int64_t audiotimestamp; ///< Audio packet timestamp
52  int sub_packet_cnt; // Subpacket counter, used while reading
53  int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container
54  int audio_framesize; /// Audio frame size from container
55  int sub_packet_lengths[16]; /// Length of each subpacket
56  int32_t deint_id; ///< deinterleaver used in audio stream
57 };
58 
59 typedef struct RMDemuxContext {
64  int audio_stream_num; ///< Stream number for audio packets
65  int audio_pkt_cnt; ///< Output packet counter
67 
68 static int rm_read_close(AVFormatContext *s);
69 
70 static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
71 {
72  int i;
73  char *q, r;
74 
75  q = buf;
76  for(i=0;i<len;i++) {
77  r = avio_r8(pb);
78  if (i < buf_size - 1)
79  *q++ = r;
80  }
81  if (buf_size > 0) *q = '\0';
82 }
83 
84 static void get_str8(AVIOContext *pb, char *buf, int buf_size)
85 {
86  get_strl(pb, buf, buf_size, avio_r8(pb));
87 }
88 
89 static int rm_read_extradata(AVIOContext *pb, AVCodecContext *avctx, unsigned size)
90 {
91  if (size >= 1<<24) {
92  av_log(avctx, AV_LOG_ERROR, "extradata size %u too large\n", size);
93  return -1;
94  }
95  if (ff_get_extradata(avctx, pb, size) < 0)
96  return AVERROR(ENOMEM);
97  return 0;
98 }
99 
100 static void rm_read_metadata(AVFormatContext *s, AVIOContext *pb, int wide)
101 {
102  char buf[1024];
103  int i;
104 
105  for (i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) {
106  int len = wide ? avio_rb16(pb) : avio_r8(pb);
107  get_strl(pb, buf, sizeof(buf), len);
108  av_dict_set(&s->metadata, ff_rm_metadata[i], buf, 0);
109  }
110 }
111 
113 {
114  RMStream *rms = av_mallocz(sizeof(RMStream));
115  if (!rms)
116  return NULL;
117  rms->curpic_num = -1;
118  return rms;
119 }
120 
122 {
123  av_free_packet(&rms->pkt);
124 }
125 
127  AVStream *st, RMStream *ast, int read_all)
128 {
129  char buf[256];
130  uint32_t version;
131  int ret;
132 
133  /* ra type header */
134  version = avio_rb16(pb); /* version */
135  if (version == 3) {
136  unsigned bytes_per_minute;
137  int header_size = avio_rb16(pb);
138  int64_t startpos = avio_tell(pb);
139  avio_skip(pb, 8);
140  bytes_per_minute = avio_rb16(pb);
141  avio_skip(pb, 4);
142  rm_read_metadata(s, pb, 0);
143  if ((startpos + header_size) >= avio_tell(pb) + 2) {
144  // fourcc (should always be "lpcJ")
145  avio_r8(pb);
146  get_str8(pb, buf, sizeof(buf));
147  }
148  // Skip extra header crap (this should never happen)
149  if ((startpos + header_size) > avio_tell(pb))
150  avio_skip(pb, header_size + startpos - avio_tell(pb));
151  if (bytes_per_minute)
152  st->codec->bit_rate = 8LL * bytes_per_minute / 60;
153  st->codec->sample_rate = 8000;
154  st->codec->channels = 1;
158  ast->deint_id = DEINT_ID_INT0;
159  } else {
160  int flavor, sub_packet_h, coded_framesize, sub_packet_size;
161  int codecdata_length;
162  unsigned bytes_per_minute;
163  /* old version (4) */
164  avio_skip(pb, 2); /* unused */
165  avio_rb32(pb); /* .ra4 */
166  avio_rb32(pb); /* data size */
167  avio_rb16(pb); /* version2 */
168  avio_rb32(pb); /* header size */
169  flavor= avio_rb16(pb); /* add codec info / flavor */
170  ast->coded_framesize = coded_framesize = avio_rb32(pb); /* coded frame size */
171  avio_rb32(pb); /* ??? */
172  bytes_per_minute = avio_rb32(pb);
173  if (version == 4) {
174  if (bytes_per_minute)
175  st->codec->bit_rate = 8LL * bytes_per_minute / 60;
176  }
177  avio_rb32(pb); /* ??? */
178  ast->sub_packet_h = sub_packet_h = avio_rb16(pb); /* 1 */
179  st->codec->block_align= avio_rb16(pb); /* frame size */
180  ast->sub_packet_size = sub_packet_size = avio_rb16(pb); /* sub packet size */
181  avio_rb16(pb); /* ??? */
182  if (version == 5) {
183  avio_rb16(pb); avio_rb16(pb); avio_rb16(pb);
184  }
185  st->codec->sample_rate = avio_rb16(pb);
186  avio_rb32(pb);
187  st->codec->channels = avio_rb16(pb);
188  if (version == 5) {
189  ast->deint_id = avio_rl32(pb);
190  avio_read(pb, buf, 4);
191  buf[4] = 0;
192  } else {
193  AV_WL32(buf, 0);
194  get_str8(pb, buf, sizeof(buf)); /* desc */
195  ast->deint_id = AV_RL32(buf);
196  get_str8(pb, buf, sizeof(buf)); /* desc */
197  }
199  st->codec->codec_tag = AV_RL32(buf);
201  st->codec->codec_tag);
202 
203  switch (st->codec->codec_id) {
204  case AV_CODEC_ID_AC3:
206  break;
207  case AV_CODEC_ID_RA_288:
208  st->codec->extradata_size= 0;
209  ast->audio_framesize = st->codec->block_align;
210  st->codec->block_align = coded_framesize;
211  break;
212  case AV_CODEC_ID_COOK:
214  case AV_CODEC_ID_ATRAC3:
215  case AV_CODEC_ID_SIPR:
216  if (read_all) {
217  codecdata_length = 0;
218  } else {
219  avio_rb16(pb); avio_r8(pb);
220  if (version == 5)
221  avio_r8(pb);
222  codecdata_length = avio_rb32(pb);
223  if(codecdata_length + AV_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
224  av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
225  return -1;
226  }
227  }
228 
229  ast->audio_framesize = st->codec->block_align;
230  if (st->codec->codec_id == AV_CODEC_ID_SIPR) {
231  if (flavor > 3) {
232  av_log(s, AV_LOG_ERROR, "bad SIPR file flavor %d\n",
233  flavor);
234  return -1;
235  }
236  st->codec->block_align = ff_sipr_subpk_size[flavor];
237  } else {
238  if(sub_packet_size <= 0){
239  av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n");
240  return -1;
241  }
242  st->codec->block_align = ast->sub_packet_size;
243  }
244  if ((ret = rm_read_extradata(pb, st->codec, codecdata_length)) < 0)
245  return ret;
246 
247  break;
248  case AV_CODEC_ID_AAC:
249  avio_rb16(pb); avio_r8(pb);
250  if (version == 5)
251  avio_r8(pb);
252  codecdata_length = avio_rb32(pb);
253  if(codecdata_length + AV_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){
254  av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
255  return -1;
256  }
257  if (codecdata_length >= 1) {
258  avio_r8(pb);
259  if ((ret = rm_read_extradata(pb, st->codec, codecdata_length - 1)) < 0)
260  return ret;
261  }
262  break;
263  }
264  switch (ast->deint_id) {
265  case DEINT_ID_INT4:
266  if (ast->coded_framesize > ast->audio_framesize ||
267  sub_packet_h <= 1 ||
268  ast->coded_framesize * sub_packet_h > (2 + (sub_packet_h & 1)) * ast->audio_framesize)
269  return AVERROR_INVALIDDATA;
270  if (ast->coded_framesize * sub_packet_h != 2*ast->audio_framesize) {
271  avpriv_request_sample(s, "mismatching interleaver parameters");
272  return AVERROR_INVALIDDATA;
273  }
274  break;
275  case DEINT_ID_GENR:
276  if (ast->sub_packet_size <= 0 ||
277  ast->sub_packet_size > ast->audio_framesize)
278  return AVERROR_INVALIDDATA;
279  if (ast->audio_framesize % ast->sub_packet_size)
280  return AVERROR_INVALIDDATA;
281  break;
282  case DEINT_ID_SIPR:
283  case DEINT_ID_INT0:
284  case DEINT_ID_VBRS:
285  case DEINT_ID_VBRF:
286  break;
287  default:
288  av_log(s, AV_LOG_ERROR ,"Unknown interleaver %"PRIX32"\n", ast->deint_id);
289  return AVERROR_INVALIDDATA;
290  }
291  if (ast->deint_id == DEINT_ID_INT4 ||
292  ast->deint_id == DEINT_ID_GENR ||
293  ast->deint_id == DEINT_ID_SIPR) {
294  if (st->codec->block_align <= 0 ||
295  ast->audio_framesize * sub_packet_h > (unsigned)INT_MAX ||
296  ast->audio_framesize * sub_packet_h < st->codec->block_align)
297  return AVERROR_INVALIDDATA;
298  if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0)
299  return AVERROR(ENOMEM);
300  }
301 
302  if (read_all) {
303  avio_r8(pb);
304  avio_r8(pb);
305  avio_r8(pb);
306  rm_read_metadata(s, pb, 0);
307  }
308  }
309  return 0;
310 }
311 
313  AVStream *st, RMStream *rst,
314  unsigned int codec_data_size, const uint8_t *mime)
315 {
316  unsigned int v;
317  int size;
318  int64_t codec_pos;
319  int ret;
320 
321  if (codec_data_size > INT_MAX)
322  return AVERROR_INVALIDDATA;
323  if (codec_data_size == 0)
324  return 0;
325 
326  avpriv_set_pts_info(st, 64, 1, 1000);
327  codec_pos = avio_tell(pb);
328  v = avio_rb32(pb);
329 
330  if (v == MKTAG(0xfd, 'a', 'r', '.')) {
331  /* ra type header */
332  if (rm_read_audio_stream_info(s, pb, st, rst, 0))
333  return -1;
334  } else if (v == MKBETAG('L', 'S', 'D', ':')) {
335  avio_seek(pb, -4, SEEK_CUR);
336  if ((ret = rm_read_extradata(pb, st->codec, codec_data_size)) < 0)
337  return ret;
338 
340  st->codec->codec_tag = AV_RL32(st->codec->extradata);
342  st->codec->codec_tag);
343  } else if(mime && !strcmp(mime, "logical-fileinfo")){
344  int stream_count, rule_count, property_count, i;
345  ff_free_stream(s, st);
346  if (avio_rb16(pb) != 0) {
347  av_log(s, AV_LOG_WARNING, "Unsupported version\n");
348  goto skip;
349  }
350  stream_count = avio_rb16(pb);
351  avio_skip(pb, 6*stream_count);
352  rule_count = avio_rb16(pb);
353  avio_skip(pb, 2*rule_count);
354  property_count = avio_rb16(pb);
355  for(i=0; i<property_count; i++){
356  uint8_t name[128], val[128];
357  avio_rb32(pb);
358  if (avio_rb16(pb) != 0) {
359  av_log(s, AV_LOG_WARNING, "Unsupported Name value property version\n");
360  goto skip; //FIXME skip just this one
361  }
362  get_str8(pb, name, sizeof(name));
363  switch(avio_rb32(pb)) {
364  case 2: get_strl(pb, val, sizeof(val), avio_rb16(pb));
365  av_dict_set(&s->metadata, name, val, 0);
366  break;
367  default: avio_skip(pb, avio_rb16(pb));
368  }
369  }
370  } else {
371  int fps;
372  if (avio_rl32(pb) != MKTAG('V', 'I', 'D', 'O')) {
373  fail1:
374  av_log(s, AV_LOG_WARNING, "Unsupported stream type %08x\n", v);
375  goto skip;
376  }
377  st->codec->codec_tag = avio_rl32(pb);
379  st->codec->codec_tag);
380  av_log(s, AV_LOG_TRACE, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0'));
381  if (st->codec->codec_id == AV_CODEC_ID_NONE)
382  goto fail1;
383  st->codec->width = avio_rb16(pb);
384  st->codec->height = avio_rb16(pb);
385  avio_skip(pb, 2); // looks like bits per sample
386  avio_skip(pb, 4); // always zero?
389  fps = avio_rb32(pb);
390 
391  if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (avio_tell(pb) - codec_pos))) < 0)
392  return ret;
393 
394  if (fps > 0) {
396  0x10000, fps, (1 << 30) - 1);
397 #if FF_API_R_FRAME_RATE
398  st->r_frame_rate = st->avg_frame_rate;
399 #endif
400  } else if (s->error_recognition & AV_EF_EXPLODE) {
401  av_log(s, AV_LOG_ERROR, "Invalid framerate\n");
402  return AVERROR_INVALIDDATA;
403  }
404  }
405 
406 skip:
407  /* skip codec info */
408  size = avio_tell(pb) - codec_pos;
409  if (codec_data_size >= size) {
410  avio_skip(pb, codec_data_size - size);
411  } else {
412  av_log(s, AV_LOG_WARNING, "codec_data_size %u < size %d\n", codec_data_size, size);
413  }
414 
415  return 0;
416 }
417 
418 /** this function assumes that the demuxer has already seeked to the start
419  * of the INDX chunk, and will bail out if not. */
421 {
422  AVIOContext *pb = s->pb;
423  unsigned int size, n_pkts, str_id, next_off, n, pos, pts;
424  AVStream *st;
425 
426  do {
427  if (avio_rl32(pb) != MKTAG('I','N','D','X'))
428  return -1;
429  size = avio_rb32(pb);
430  if (size < 20)
431  return -1;
432  avio_skip(pb, 2);
433  n_pkts = avio_rb32(pb);
434  str_id = avio_rb16(pb);
435  next_off = avio_rb32(pb);
436  for (n = 0; n < s->nb_streams; n++)
437  if (s->streams[n]->id == str_id) {
438  st = s->streams[n];
439  break;
440  }
441  if (n == s->nb_streams) {
442  av_log(s, AV_LOG_ERROR,
443  "Invalid stream index %d for index at pos %"PRId64"\n",
444  str_id, avio_tell(pb));
445  goto skip;
446  } else if ((avio_size(pb) - avio_tell(pb)) / 14 < n_pkts) {
447  av_log(s, AV_LOG_ERROR,
448  "Nr. of packets in packet index for stream index %d "
449  "exceeds filesize (%"PRId64" at %"PRId64" = %"PRId64")\n",
450  str_id, avio_size(pb), avio_tell(pb),
451  (avio_size(pb) - avio_tell(pb)) / 14);
452  goto skip;
453  }
454 
455  for (n = 0; n < n_pkts; n++) {
456  avio_skip(pb, 2);
457  pts = avio_rb32(pb);
458  pos = avio_rb32(pb);
459  avio_skip(pb, 4); /* packet no. */
460 
461  av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME);
462  }
463 
464 skip:
465  if (next_off && avio_tell(pb) < next_off &&
466  avio_seek(pb, next_off, SEEK_SET) < 0) {
467  av_log(s, AV_LOG_ERROR,
468  "Non-linear index detected, not supported\n");
469  return -1;
470  }
471  } while (next_off);
472 
473  return 0;
474 }
475 
477 {
478  RMDemuxContext *rm = s->priv_data;
479  AVStream *st;
480 
481  rm->old_format = 1;
482  st = avformat_new_stream(s, NULL);
483  if (!st)
484  return -1;
486  if (!st->priv_data)
487  return AVERROR(ENOMEM);
488  return rm_read_audio_stream_info(s, s->pb, st, st->priv_data, 1);
489 }
490 
492 {
493  RMDemuxContext *rm = s->priv_data;
494  AVStream *st;
495  AVIOContext *pb = s->pb;
496  unsigned int tag;
497  int tag_size;
498  unsigned int start_time, duration;
499  unsigned int data_off = 0, indx_off = 0;
500  char buf[128], mime[128];
501  int flags = 0;
502  int ret = -1;
503  unsigned size, v;
504  int64_t codec_pos;
505 
506  tag = avio_rl32(pb);
507  if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
508  /* very old .ra format */
509  return rm_read_header_old(s);
510  } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
511  return AVERROR(EIO);
512  }
513 
514  tag_size = avio_rb32(pb);
515  avio_skip(pb, tag_size - 8);
516 
517  for(;;) {
518  if (avio_feof(pb))
519  goto fail;
520  tag = avio_rl32(pb);
521  tag_size = avio_rb32(pb);
522  avio_rb16(pb);
523  av_log(s, AV_LOG_TRACE, "tag=%c%c%c%c (%08x) size=%d\n",
524  (tag ) & 0xff,
525  (tag >> 8) & 0xff,
526  (tag >> 16) & 0xff,
527  (tag >> 24) & 0xff,
528  tag,
529  tag_size);
530  if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
531  goto fail;
532  switch(tag) {
533  case MKTAG('P', 'R', 'O', 'P'):
534  /* file header */
535  avio_rb32(pb); /* max bit rate */
536  avio_rb32(pb); /* avg bit rate */
537  avio_rb32(pb); /* max packet size */
538  avio_rb32(pb); /* avg packet size */
539  avio_rb32(pb); /* nb packets */
540  duration = avio_rb32(pb); /* duration */
541  s->duration = av_rescale(duration, AV_TIME_BASE, 1000);
542  avio_rb32(pb); /* preroll */
543  indx_off = avio_rb32(pb); /* index offset */
544  data_off = avio_rb32(pb); /* data offset */
545  avio_rb16(pb); /* nb streams */
546  flags = avio_rb16(pb); /* flags */
547  break;
548  case MKTAG('C', 'O', 'N', 'T'):
549  rm_read_metadata(s, pb, 1);
550  break;
551  case MKTAG('M', 'D', 'P', 'R'):
552  st = avformat_new_stream(s, NULL);
553  if (!st) {
554  ret = AVERROR(ENOMEM);
555  goto fail;
556  }
557  st->id = avio_rb16(pb);
558  avio_rb32(pb); /* max bit rate */
559  st->codec->bit_rate = avio_rb32(pb); /* bit rate */
560  avio_rb32(pb); /* max packet size */
561  avio_rb32(pb); /* avg packet size */
562  start_time = avio_rb32(pb); /* start time */
563  avio_rb32(pb); /* preroll */
564  duration = avio_rb32(pb); /* duration */
565  st->start_time = start_time;
566  st->duration = duration;
567  if(duration>0)
569  get_str8(pb, buf, sizeof(buf)); /* desc */
570  get_str8(pb, mime, sizeof(mime)); /* mimetype */
573  if (!st->priv_data)
574  return AVERROR(ENOMEM);
575 
576  size = avio_rb32(pb);
577  codec_pos = avio_tell(pb);
578 
579  ffio_ensure_seekback(pb, 4);
580  v = avio_rb32(pb);
581  if (v == MKBETAG('M', 'L', 'T', 'I')) {
582  int number_of_streams = avio_rb16(pb);
583  int number_of_mdpr;
584  int i;
585  unsigned size2;
586  for (i = 0; i<number_of_streams; i++)
587  avio_rb16(pb);
588  number_of_mdpr = avio_rb16(pb);
589  if (number_of_mdpr != 1) {
590  avpriv_request_sample(s, "MLTI with multiple (%d) MDPR", number_of_mdpr);
591  }
592  for (i = 0; i < number_of_mdpr; i++) {
593  AVStream *st2;
594  if (i > 0) {
595  st2 = avformat_new_stream(s, NULL);
596  if (!st2) {
597  ret = AVERROR(ENOMEM);
598  goto fail;
599  }
600  st2->id = st->id + (i<<16);
601  st2->codec->bit_rate = st->codec->bit_rate;
602  st2->start_time = st->start_time;
603  st2->duration = st->duration;
606  if (!st2->priv_data)
607  return AVERROR(ENOMEM);
608  } else
609  st2 = st;
610 
611  size2 = avio_rb32(pb);
612  if (ff_rm_read_mdpr_codecdata(s, s->pb, st2, st2->priv_data,
613  size2, mime) < 0)
614  goto fail;
615  }
616  avio_seek(pb, codec_pos + size, SEEK_SET);
617  } else {
618  avio_skip(pb, -4);
619  if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
620  size, mime) < 0)
621  goto fail;
622  }
623 
624  break;
625  case MKTAG('D', 'A', 'T', 'A'):
626  goto header_end;
627  default:
628  /* unknown tag: skip it */
629  avio_skip(pb, tag_size - 10);
630  break;
631  }
632  }
633  header_end:
634  rm->nb_packets = avio_rb32(pb); /* number of packets */
635  if (!rm->nb_packets && (flags & 4))
636  rm->nb_packets = 3600 * 25;
637  avio_rb32(pb); /* next data header */
638 
639  if (!data_off)
640  data_off = avio_tell(pb) - 18;
641  if (indx_off && pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) &&
642  avio_seek(pb, indx_off, SEEK_SET) >= 0) {
643  rm_read_index(s);
644  avio_seek(pb, data_off + 18, SEEK_SET);
645  }
646 
647  return 0;
648 
649 fail:
650  rm_read_close(s);
651  return ret;
652 }
653 
654 static int get_num(AVIOContext *pb, int *len)
655 {
656  int n, n1;
657 
658  n = avio_rb16(pb);
659  (*len)-=2;
660  n &= 0x7FFF;
661  if (n >= 0x4000) {
662  return n - 0x4000;
663  } else {
664  n1 = avio_rb16(pb);
665  (*len)-=2;
666  return (n << 16) | n1;
667  }
668 }
669 
670 /* multiple of 20 bytes for ra144 (ugly) */
671 #define RAW_PACKET_SIZE 1000
672 
673 static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){
674  RMDemuxContext *rm = s->priv_data;
675  AVIOContext *pb = s->pb;
676  AVStream *st;
677  uint32_t state=0xFFFFFFFF;
678 
679  while(!avio_feof(pb)){
680  int len, num, i;
681  int mlti_id;
682  *pos= avio_tell(pb) - 3;
683  if(rm->remaining_len > 0){
684  num= rm->current_stream;
685  mlti_id = 0;
686  len= rm->remaining_len;
687  *timestamp = AV_NOPTS_VALUE;
688  *flags= 0;
689  }else{
690  state= (state<<8) + avio_r8(pb);
691 
692  if(state == MKBETAG('I', 'N', 'D', 'X')){
693  int n_pkts, expected_len;
694  len = avio_rb32(pb);
695  avio_skip(pb, 2);
696  n_pkts = avio_rb32(pb);
697  expected_len = 20 + n_pkts * 14;
698  if (len == 20)
699  /* some files don't add index entries to chunk size... */
700  len = expected_len;
701  else if (len != expected_len)
703  "Index size %d (%d pkts) is wrong, should be %d.\n",
704  len, n_pkts, expected_len);
705  len -= 14; // we already read part of the index header
706  if(len<0)
707  continue;
708  goto skip;
709  } else if (state == MKBETAG('D','A','T','A')) {
711  "DATA tag in middle of chunk, file may be broken.\n");
712  }
713 
714  if(state > (unsigned)0xFFFF || state <= 12)
715  continue;
716  len=state - 12;
717  state= 0xFFFFFFFF;
718 
719  num = avio_rb16(pb);
720  *timestamp = avio_rb32(pb);
721  mlti_id = (avio_r8(pb)>>1)-1<<16;
722  mlti_id = FFMAX(mlti_id, 0);
723  *flags = avio_r8(pb); /* flags */
724  }
725  for(i=0;i<s->nb_streams;i++) {
726  st = s->streams[i];
727  if (mlti_id + num == st->id)
728  break;
729  }
730  if (i == s->nb_streams) {
731 skip:
732  /* skip packet if unknown number */
733  avio_skip(pb, len);
734  rm->remaining_len = 0;
735  continue;
736  }
737  *stream_index= i;
738 
739  return len;
740  }
741  return -1;
742 }
743 
745  RMDemuxContext *rm, RMStream *vst,
746  AVPacket *pkt, int len, int *pseq,
747  int64_t *timestamp)
748 {
749  int hdr;
750  int seq = 0, pic_num = 0, len2 = 0, pos = 0; //init to silence compiler warning
751  int type;
752  int ret;
753 
754  hdr = avio_r8(pb); len--;
755  type = hdr >> 6;
756 
757  if(type != 3){ // not frame as a part of packet
758  seq = avio_r8(pb); len--;
759  }
760  if(type != 1){ // not whole frame
761  len2 = get_num(pb, &len);
762  pos = get_num(pb, &len);
763  pic_num = avio_r8(pb); len--;
764  }
765  if(len<0) {
766  av_log(s, AV_LOG_ERROR, "Insufficient data\n");
767  return -1;
768  }
769  rm->remaining_len = len;
770  if(type&1){ // frame, not slice
771  if(type == 3){ // frame as a part of packet
772  len= len2;
773  *timestamp = pos;
774  }
775  if(rm->remaining_len < len) {
776  av_log(s, AV_LOG_ERROR, "Insufficient remaining len\n");
777  return -1;
778  }
779  rm->remaining_len -= len;
780  if(av_new_packet(pkt, len + 9) < 0)
781  return AVERROR(EIO);
782  pkt->data[0] = 0;
783  AV_WL32(pkt->data + 1, 1);
784  AV_WL32(pkt->data + 5, 0);
785  if ((ret = avio_read(pb, pkt->data + 9, len)) != len) {
786  av_free_packet(pkt);
787  av_log(s, AV_LOG_ERROR, "Failed to read %d bytes\n", len);
788  return ret < 0 ? ret : AVERROR(EIO);
789  }
790  return 0;
791  }
792  //now we have to deal with single slice
793 
794  *pseq = seq;
795  if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){
796  if (len2 > ffio_limit(pb, len2)) {
797  av_log(s, AV_LOG_ERROR, "Impossibly sized packet\n");
798  return AVERROR_INVALIDDATA;
799  }
800  vst->slices = ((hdr & 0x3F) << 1) + 1;
801  vst->videobufsize = len2 + 8*vst->slices + 1;
802  av_free_packet(&vst->pkt); //FIXME this should be output.
803  if(av_new_packet(&vst->pkt, vst->videobufsize) < 0)
804  return AVERROR(ENOMEM);
805  memset(vst->pkt.data, 0, vst->pkt.size);
806  vst->videobufpos = 8*vst->slices + 1;
807  vst->cur_slice = 0;
808  vst->curpic_num = pic_num;
809  vst->pktpos = avio_tell(pb);
810  }
811  if(type == 2)
812  len = FFMIN(len, pos);
813 
814  if(++vst->cur_slice > vst->slices) {
815  av_log(s, AV_LOG_ERROR, "cur slice %d, too large\n", vst->cur_slice);
816  return 1;
817  }
818  if(!vst->pkt.data)
819  return AVERROR(ENOMEM);
820  AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1);
821  AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1);
822  if(vst->videobufpos + len > vst->videobufsize) {
823  av_log(s, AV_LOG_ERROR, "outside videobufsize\n");
824  return 1;
825  }
826  if (avio_read(pb, vst->pkt.data + vst->videobufpos, len) != len)
827  return AVERROR(EIO);
828  vst->videobufpos += len;
829  rm->remaining_len-= len;
830 
831  if (type == 2 || vst->videobufpos == vst->videobufsize) {
832  vst->pkt.data[0] = vst->cur_slice-1;
833  *pkt= vst->pkt;
834  vst->pkt.data= NULL;
835  vst->pkt.size= 0;
836  vst->pkt.buf = NULL;
837 #if FF_API_DESTRUCT_PACKET
839  vst->pkt.destruct = NULL;
841 #endif
842  if(vst->slices != vst->cur_slice) //FIXME find out how to set slices correct from the begin
843  memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices,
844  vst->videobufpos - 1 - 8*vst->slices);
845  pkt->size = vst->videobufpos + 8*(vst->cur_slice - vst->slices);
846  pkt->pts = AV_NOPTS_VALUE;
847  pkt->pos = vst->pktpos;
848  vst->slices = 0;
849  return 0;
850  }
851 
852  return 1;
853 }
854 
855 static inline void
857 {
858  uint8_t *ptr;
859  int j;
860 
861  if (st->codec->codec_id == AV_CODEC_ID_AC3) {
862  ptr = pkt->data;
863  for (j=0;j<pkt->size;j+=2) {
864  FFSWAP(int, ptr[0], ptr[1]);
865  ptr += 2;
866  }
867  }
868 }
869 
870 static int readfull(AVFormatContext *s, AVIOContext *pb, uint8_t *dst, int n) {
871  int ret = avio_read(pb, dst, n);
872  if (ret != n) {
873  if (ret >= 0) memset(dst + ret, 0, n - ret);
874  else memset(dst , 0, n);
875  av_log(s, AV_LOG_ERROR, "Failed to fully read block\n");
876  }
877  return ret;
878 }
879 
880 int
882  AVStream *st, RMStream *ast, int len, AVPacket *pkt,
883  int *seq, int flags, int64_t timestamp)
884 {
885  RMDemuxContext *rm = s->priv_data;
886  int ret;
887 
888  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
889  rm->current_stream= st->id;
890  ret = rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, &timestamp);
891  if(ret)
892  return ret < 0 ? ret : -1; //got partial frame or error
893  } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
894  if ((ast->deint_id == DEINT_ID_GENR) ||
895  (ast->deint_id == DEINT_ID_INT4) ||
896  (ast->deint_id == DEINT_ID_SIPR)) {
897  int x;
898  int sps = ast->sub_packet_size;
899  int cfs = ast->coded_framesize;
900  int h = ast->sub_packet_h;
901  int y = ast->sub_packet_cnt;
902  int w = ast->audio_framesize;
903 
904  if (flags & 2)
905  y = ast->sub_packet_cnt = 0;
906  if (!y)
907  ast->audiotimestamp = timestamp;
908 
909  switch (ast->deint_id) {
910  case DEINT_ID_INT4:
911  for (x = 0; x < h/2; x++)
912  readfull(s, pb, ast->pkt.data+x*2*w+y*cfs, cfs);
913  break;
914  case DEINT_ID_GENR:
915  for (x = 0; x < w/sps; x++)
916  readfull(s, pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
917  break;
918  case DEINT_ID_SIPR:
919  readfull(s, pb, ast->pkt.data + y * w, w);
920  break;
921  }
922 
923  if (++(ast->sub_packet_cnt) < h)
924  return -1;
925  if (ast->deint_id == DEINT_ID_SIPR)
926  ff_rm_reorder_sipr_data(ast->pkt.data, h, w);
927 
928  ast->sub_packet_cnt = 0;
929  rm->audio_stream_num = st->index;
930  rm->audio_pkt_cnt = h * w / st->codec->block_align;
931  } else if ((ast->deint_id == DEINT_ID_VBRF) ||
932  (ast->deint_id == DEINT_ID_VBRS)) {
933  int x;
934  rm->audio_stream_num = st->index;
935  ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4;
936  if (ast->sub_packet_cnt) {
937  for (x = 0; x < ast->sub_packet_cnt; x++)
938  ast->sub_packet_lengths[x] = avio_rb16(pb);
939  rm->audio_pkt_cnt = ast->sub_packet_cnt;
940  ast->audiotimestamp = timestamp;
941  } else
942  return -1;
943  } else {
944  if ((ret = av_get_packet(pb, pkt, len)) < 0)
945  return ret;
946  rm_ac3_swap_bytes(st, pkt);
947  }
948  } else {
949  if ((ret = av_get_packet(pb, pkt, len)) < 0)
950  return ret;
951  }
952 
953  pkt->stream_index = st->index;
954 
955 #if 0
956  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
957  if(st->codec->codec_id == AV_CODEC_ID_RV20){
958  int seq= 128*(pkt->data[2]&0x7F) + (pkt->data[3]>>1);
959  av_log(s, AV_LOG_DEBUG, "%d %"PRId64" %d\n", *timestamp, *timestamp*512LL/25, seq);
960 
961  seq |= (timestamp&~0x3FFF);
962  if(seq - timestamp > 0x2000) seq -= 0x4000;
963  if(seq - timestamp < -0x2000) seq += 0x4000;
964  }
965  }
966 #endif
967 
968  pkt->pts = timestamp;
969  if (flags & 2)
970  pkt->flags |= AV_PKT_FLAG_KEY;
971 
972  return st->codec->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0;
973 }
974 
975 int
977  AVStream *st, RMStream *ast, AVPacket *pkt)
978 {
979  RMDemuxContext *rm = s->priv_data;
980 
981  av_assert0 (rm->audio_pkt_cnt > 0);
982 
983  if (ast->deint_id == DEINT_ID_VBRF ||
984  ast->deint_id == DEINT_ID_VBRS) {
985  int ret = av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]);
986  if (ret < 0)
987  return ret;
988  } else {
989  int ret = av_new_packet(pkt, st->codec->block_align);
990  if (ret < 0)
991  return ret;
992  memcpy(pkt->data, ast->pkt.data + st->codec->block_align * //FIXME avoid this
993  (ast->sub_packet_h * ast->audio_framesize / st->codec->block_align - rm->audio_pkt_cnt),
994  st->codec->block_align);
995  }
996  rm->audio_pkt_cnt--;
997  if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) {
999  pkt->flags = AV_PKT_FLAG_KEY;
1000  } else
1001  pkt->flags = 0;
1002  pkt->stream_index = st->index;
1003 
1004  return rm->audio_pkt_cnt;
1005 }
1006 
1008 {
1009  RMDemuxContext *rm = s->priv_data;
1010  AVStream *st = NULL; // init to silence compiler warning
1011  int i, len, res, seq = 1;
1012  int64_t timestamp, pos;
1013  int flags;
1014 
1015  for (;;) {
1016  if (rm->audio_pkt_cnt) {
1017  // If there are queued audio packet return them first
1018  st = s->streams[rm->audio_stream_num];
1019  res = ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
1020  if(res < 0)
1021  return res;
1022  flags = 0;
1023  } else {
1024  if (rm->old_format) {
1025  RMStream *ast;
1026 
1027  st = s->streams[0];
1028  ast = st->priv_data;
1029  timestamp = AV_NOPTS_VALUE;
1030  len = !ast->audio_framesize ? RAW_PACKET_SIZE :
1031  ast->coded_framesize * ast->sub_packet_h / 2;
1032  flags = (seq++ == 1) ? 2 : 0;
1033  pos = avio_tell(s->pb);
1034  } else {
1035  len = rm_sync(s, &timestamp, &flags, &i, &pos);
1036  if (len > 0)
1037  st = s->streams[i];
1038  }
1039 
1040  if (len <= 0 || avio_feof(s->pb))
1041  return AVERROR(EIO);
1042 
1043  res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
1044  &seq, flags, timestamp);
1045  if (res < -1)
1046  return res;
1047  if((flags&2) && (seq&0x7F) == 1)
1048  av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
1049  if (res)
1050  continue;
1051  }
1052 
1053  if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
1054  || st->discard >= AVDISCARD_ALL){
1055  av_free_packet(pkt);
1056  } else
1057  break;
1058  }
1059 
1060  return 0;
1061 }
1062 
1064 {
1065  int i;
1066 
1067  for (i=0;i<s->nb_streams;i++)
1069 
1070  return 0;
1071 }
1072 
1073 static int rm_probe(AVProbeData *p)
1074 {
1075  /* check file header */
1076  if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
1077  p->buf[2] == 'M' && p->buf[3] == 'F' &&
1078  p->buf[4] == 0 && p->buf[5] == 0) ||
1079  (p->buf[0] == '.' && p->buf[1] == 'r' &&
1080  p->buf[2] == 'a' && p->buf[3] == 0xfd))
1081  return AVPROBE_SCORE_MAX;
1082  else
1083  return 0;
1084 }
1085 
1086 static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
1087  int64_t *ppos, int64_t pos_limit)
1088 {
1089  RMDemuxContext *rm = s->priv_data;
1090  int64_t pos, dts;
1091  int stream_index2, flags, len, h;
1092 
1093  pos = *ppos;
1094 
1095  if(rm->old_format)
1096  return AV_NOPTS_VALUE;
1097 
1098  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1099  return AV_NOPTS_VALUE;
1100 
1101  rm->remaining_len=0;
1102  for(;;){
1103  int seq=1;
1104  AVStream *st;
1105 
1106  len = rm_sync(s, &dts, &flags, &stream_index2, &pos);
1107  if(len<0)
1108  return AV_NOPTS_VALUE;
1109 
1110  st = s->streams[stream_index2];
1111  if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
1112  h= avio_r8(s->pb); len--;
1113  if(!(h & 0x40)){
1114  seq = avio_r8(s->pb); len--;
1115  }
1116  }
1117 
1118  if((flags&2) && (seq&0x7F) == 1){
1119  av_log(s, AV_LOG_TRACE, "%d %d-%d %"PRId64" %d\n",
1120  flags, stream_index2, stream_index, dts, seq);
1121  av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME);
1122  if(stream_index2 == stream_index)
1123  break;
1124  }
1125 
1126  avio_skip(s->pb, len);
1127  }
1128  *ppos = pos;
1129  return dts;
1130 }
1131 
1132 static int rm_read_seek(AVFormatContext *s, int stream_index,
1133  int64_t pts, int flags)
1134 {
1135  RMDemuxContext *rm = s->priv_data;
1136 
1137  if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0)
1138  return -1;
1139  rm->audio_pkt_cnt = 0;
1140  return 0;
1141 }
1142 
1143 
1145  .name = "rm",
1146  .long_name = NULL_IF_CONFIG_SMALL("RealMedia"),
1147  .priv_data_size = sizeof(RMDemuxContext),
1148  .read_probe = rm_probe,
1152  .read_timestamp = rm_read_dts,
1154 };
1155 
1157  .name = "rdt",
1158  .long_name = NULL_IF_CONFIG_SMALL("RDT demuxer"),
1159  .priv_data_size = sizeof(RMDemuxContext),
1161  .flags = AVFMT_NOFILE,
1162 };
static int get_num(AVIOContext *pb, int *len)
Definition: rmdec.c:654
#define NULL
Definition: coverity.c:32
full parsing and interpolation of timestamps for frames not starting on a packet boundary ...
Definition: avformat.h:776
#define RAW_PACKET_SIZE
Definition: rmdec.c:671
const char const char void * val
Definition: avisynth_c.h:634
int remaining_len
Definition: rmdec.c:63
discard all frames except keyframes
Definition: avcodec.h:688
float v
const char * s
Definition: avisynth_c.h:631
Bytestream IO Context.
Definition: avio.h:111
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:282
void av_free_packet(AVPacket *pkt)
Free a packet.
Definition: avpacket.c:280
#define DEINT_ID_INT0
no interleaving needed
Definition: rmdec.c:37
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
Definition: utils.c:1745
static void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
Definition: rmdec.c:70
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:2773
static int64_t rm_read_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
Definition: rmdec.c:1086
const unsigned char ff_sipr_subpk_size[4]
Definition: rmsipr.c:25
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int64_t pos
byte position in stream, -1 if unknown
Definition: avcodec.h:1448
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:4083
int ff_get_extradata(AVCodecContext *avctx, AVIOContext *pb, int size)
Allocate extradata with additional AV_INPUT_BUFFER_PADDING_SIZE at end which is always set to 0 and f...
Definition: utils.c:2945
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:153
int num
numerator
Definition: rational.h:44
int index
stream index in AVFormatContext
Definition: avformat.h:843
int size
Definition: avcodec.h:1424
Definition: rmdec.c:43
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:204
int cur_slice
Definition: rmdec.c:48
void * priv_data
Definition: avformat.h:862
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:277
int version
Definition: avisynth_c.h:629
static int rm_read_header(AVFormatContext *s)
Definition: rmdec.c:491
discard all
Definition: avcodec.h:689
static AVPacket pkt
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:675
int block_align
number of bytes per packet if constant and known or 0 Used by some WAV based audio codecs...
Definition: avcodec.h:2299
#define DEINT_ID_VBRS
VBR case for AAC.
Definition: rmdec.c:41
int videobufpos
position for the next slice in the video buffer
Definition: rmdec.c:46
Format I/O context.
Definition: avformat.h:1273
int audio_stream_num
Stream number for audio packets.
Definition: rmdec.c:64
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:1386
Public dictionary API.
int ffio_limit(AVIOContext *s, int size)
Definition: utils.c:181
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
static int64_t start_time
Definition: ffplay.c:325
uint8_t
Opaque data information usually continuous.
Definition: avutil.h:195
attribute_deprecated void(* destruct)(struct AVPacket *)
Definition: avcodec.h:1444
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:202
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:690
int id
Format-specific stream ID.
Definition: avformat.h:849
enum AVStreamParseType need_parsing
Definition: avformat.h:1034
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1617
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:3749
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:1341
int flags
Flags modifying the (de)muxer behaviour.
Definition: avformat.h:1384
uint8_t * data
Definition: avcodec.h:1423
uint32_t tag
Definition: movenc.c:1334
int curpic_num
picture number of current frame
Definition: rmdec.c:47
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:145
int av_get_packet(AVIOContext *s, AVPacket *pkt, int size)
Allocate and read the payload of a packet and initialize its fields with default values.
Definition: utils.c:244
static int rm_read_index(AVFormatContext *s)
this function assumes that the demuxer has already seeked to the start of the INDX chunk...
Definition: rmdec.c:420
ptrdiff_t size
Definition: opengl_enc.c:101
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:390
#define DEINT_ID_GENR
interleaving for Cooker/ATRAC
Definition: rmdec.c:36
static int64_t duration
Definition: ffplay.c:326
static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, RMDemuxContext *rm, RMStream *vst, AVPacket *pkt, int len, int *pseq, int64_t *timestamp)
Definition: rmdec.c:744
static void get_str8(AVIOContext *pb, char *buf, int buf_size)
Definition: rmdec.c:84
#define av_log(a,...)
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:538
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1469
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:83
#define AVINDEX_KEYFRAME
Definition: avformat.h:791
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1485
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:2901
static int rm_read_close(AVFormatContext *s)
Definition: rmdec.c:1063
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:659
#define AVERROR(e)
Definition: error.h:43
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:175
const char * r
Definition: vf_curves.c:107
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1406
simple assert() macros that are a bit more flexible than ISO C assert().
#define DEINT_ID_VBRF
VBR case for AAC.
Definition: rmdec.c:40
static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos)
Definition: rmdec.c:673
int64_t pktpos
first slice position in file
Definition: rmdec.c:49
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:925
#define FFMAX(a, b)
Definition: common.h:79
RMStream * ff_rm_alloc_rmstream(void)
Definition: rmdec.c:112
#define fail()
Definition: checkasm.h:57
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1429
uint64_t channel_layout
Audio channel layout.
Definition: avcodec.h:2323
Only parse headers, do not repack.
Definition: avformat.h:775
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:529
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:861
int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)
Reduce a fraction.
Definition: rational.c:35
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:450
common internal API header
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:1329
AVPacket pkt
place to store merged video frame / reordered audio data
Definition: rmdec.c:44
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:160
int bit_rate
the average bitrate
Definition: avcodec.h:1567
audio channel layout utility functions
int64_t av_rescale(int64_t a, int64_t b, int64_t c)
Rescale a 64-bit integer with rounding to nearest.
Definition: mathematics.c:127
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:246
static int readfull(AVFormatContext *s, AVIOContext *pb, uint8_t *dst, int n)
Definition: rmdec.c:870
#define FFMIN(a, b)
Definition: common.h:81
float y
void ff_free_stream(AVFormatContext *s, AVStream *st)
Definition: utils.c:3656
static int read_probe(AVProbeData *pd)
Definition: jvdec.c:55
int width
picture width / height.
Definition: avcodec.h:1681
AVInputFormat ff_rm_demuxer
Definition: rmdec.c:1144
static struct @197 state
int32_t
#define DEINT_ID_INT4
interleaving for 28.8
Definition: rmdec.c:38
int n
Definition: avisynth_c.h:547
static int rm_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: rmdec.c:1132
int sub_packet_cnt
Definition: rmdec.c:52
#define FF_ARRAY_ELEMS(a)
int coded_framesize
Descrambling parameters from container.
Definition: rmdec.c:53
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:623
int audio_framesize
Definition: rmdec.c:54
Stream structure.
Definition: avformat.h:842
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
static void rm_ac3_swap_bytes(AVStream *st, AVPacket *pkt)
Definition: rmdec.c:856
const AVCodecTag ff_rm_codec_tags[]
Definition: rm.c:31
enum AVMediaType codec_type
Definition: avcodec.h:1510
enum AVCodecID codec_id
Definition: avcodec.h:1519
#define DEINT_ID_SIPR
interleaving for Sipro
Definition: rmdec.c:39
int sample_rate
samples per second
Definition: avcodec.h:2262
AVIOContext * pb
I/O context.
Definition: avformat.h:1315
main external API structure.
Definition: avcodec.h:1502
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1534
static int rm_probe(AVProbeData *p)
Definition: rmdec.c:1073
void * buf
Definition: avisynth_c.h:553
GLint GLenum type
Definition: opengl_enc.c:105
int extradata_size
Definition: avcodec.h:1618
int ff_rm_parse_packet(AVFormatContext *s, AVIOContext *pb, AVStream *st, RMStream *ast, int len, AVPacket *pkt, int *seq, int flags, int64_t timestamp)
Parse one rm-stream packet from the input bytestream.
Definition: rmdec.c:881
int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)
Set the given entry in *pm, overwriting an existing entry.
Definition: dict.c:69
int ff_rm_read_mdpr_codecdata(AVFormatContext *s, AVIOContext *pb, AVStream *st, RMStream *rst, unsigned int codec_data_size, const uint8_t *mime)
Read the MDPR chunk, which contains stream-specific codec initialization parameters.
Definition: rmdec.c:312
int current_stream
Definition: rmdec.c:62
int old_format
Definition: rmdec.c:61
This structure contains the data a format has to probe a file.
Definition: avformat.h:448
int audio_pkt_cnt
Output packet counter.
Definition: rmdec.c:65
int nb_packets
Definition: rmdec.c:60
static int64_t pts
Global timestamp for the audio frames.
const char *const ff_rm_metadata[4]
Definition: rm.c:24
AVInputFormat ff_rdt_demuxer
Definition: rmdec.c:1156
static int flags
Definition: cpu.c:47
void ff_rm_free_rmstream(RMStream *rms)
Definition: rmdec.c:121
int sub_packet_h
Definition: rmdec.c:53
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:810
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:901
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:460
full parsing and repack
Definition: avformat.h:774
void ff_rm_reorder_sipr_data(uint8_t *buf, int sub_packet_h, int framesize)
Perform 4-bit block reordering for SIPR data.
Definition: rmsipr.c:41
Main libavformat public API header.
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:79
int32_t deint_id
Length of each subpacket.
Definition: rmdec.c:56
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:465
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base...
Definition: avformat.h:894
int error_recognition
Error recognition; higher values will detect more errors but may misdetect some more or less valid pa...
Definition: avformat.h:1512
int ff_rm_retrieve_cache(AVFormatContext *s, AVIOContext *pb, AVStream *st, RMStream *ast, AVPacket *pkt)
Retrieve one cached packet from the rm-context.
Definition: rmdec.c:976
int den
denominator
Definition: rational.h:45
static int rm_read_header_old(AVFormatContext *s)
Definition: rmdec.c:476
#define MKBETAG(a, b, c, d)
Definition: common.h:331
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:636
int slices
Definition: rmdec.c:48
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
int len
int channels
number of audio channels
Definition: avcodec.h:2263
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rmdec.c:1007
static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, AVStream *st, RMStream *ast, int read_all)
Definition: rmdec.c:126
void * priv_data
Format private data.
Definition: avformat.h:1301
static int rm_read_extradata(AVIOContext *pb, AVCodecContext *avctx, unsigned size)
Definition: rmdec.c:89
int64_t duration
Duration of the stream, in AV_TIME_BASE fractional seconds.
Definition: avformat.h:1368
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:628
int64_t audiotimestamp
Audio descrambling matrix parameters.
Definition: rmdec.c:51
int avio_feof(AVIOContext *s)
feof() equivalent for AVIOContext.
Definition: aviobuf.c:301
#define FFSWAP(type, a, b)
Definition: common.h:84
int stream_index
Definition: avcodec.h:1425
int videobufsize
current assembled frame size
Definition: rmdec.c:45
#define AV_CH_LAYOUT_MONO
#define MKTAG(a, b, c, d)
Definition: common.h:330
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:907
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:1061
int sub_packet_lengths[16]
Audio frame size from container.
Definition: rmdec.c:55
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:87
This structure stores compressed data.
Definition: avcodec.h:1400
static void rm_read_metadata(AVFormatContext *s, AVIOContext *pb, int wide)
Definition: rmdec.c:100
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1416
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags)
Perform a binary search using av_index_search_timestamp() and AVInputFormat.read_timestamp().
Definition: utils.c:1859
int sub_packet_size
Definition: rmdec.c:53
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
const char * name
Definition: opengl_enc.c:103