FFmpeg
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
66  int data_end;
68 
69 static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
70 {
71  int read = avio_get_str(pb, len, buf, buf_size);
72 
73  if (read > 0)
74  avio_skip(pb, len - read);
75 }
76 
77 static void get_str8(AVIOContext *pb, char *buf, int buf_size)
78 {
79  get_strl(pb, buf, buf_size, avio_r8(pb));
80 }
81 
83 {
84  if (size >= 1<<24) {
85  av_log(s, AV_LOG_ERROR, "extradata size %u too large\n", size);
86  return -1;
87  }
88  return ff_get_extradata(s, par, pb, size);
89 }
90 
91 static void rm_read_metadata(AVFormatContext *s, AVIOContext *pb, int wide)
92 {
93  char buf[1024];
94  int i;
95 
96  for (i=0; i<FF_ARRAY_ELEMS(ff_rm_metadata); i++) {
97  int len = wide ? avio_rb16(pb) : avio_r8(pb);
98  if (len > 0) {
99  get_strl(pb, buf, sizeof(buf), len);
100  av_dict_set(&s->metadata, ff_rm_metadata[i], buf, 0);
101  }
102  }
103 }
104 
106 {
107  RMStream *rms = av_mallocz(sizeof(RMStream));
108  if (!rms)
109  return NULL;
110  rms->curpic_num = -1;
111  return rms;
112 }
113 
115 {
116  if (!rms)
117  return;
118 
119  av_packet_unref(&rms->pkt);
120 }
121 
123  AVStream *st, RMStream *ast, int read_all)
124 {
125  FFStream *const sti = ffstream(st);
126  char buf[256];
127  uint32_t version;
128  int ret;
129 
130  // Duplicate tags
132  return AVERROR_INVALIDDATA;
133 
134  /* ra type header */
135  version = avio_rb16(pb); /* version */
136  if (version == 3) {
137  unsigned bytes_per_minute;
138  int header_size = avio_rb16(pb);
139  int64_t startpos = avio_tell(pb);
140  avio_skip(pb, 8);
141  bytes_per_minute = avio_rb16(pb);
142  avio_skip(pb, 4);
143  rm_read_metadata(s, pb, 0);
144  if ((startpos + header_size) >= avio_tell(pb) + 2) {
145  // fourcc (should always be "lpcJ")
146  avio_r8(pb);
147  get_str8(pb, buf, sizeof(buf));
148  }
149  // Skip extra header crap (this should never happen)
150  if ((startpos + header_size) > avio_tell(pb))
151  avio_skip(pb, header_size + startpos - avio_tell(pb));
152  if (bytes_per_minute)
153  st->codecpar->bit_rate = 8LL * bytes_per_minute / 60;
154  st->codecpar->sample_rate = 8000;
155  st->codecpar->channels = 1;
159  ast->deint_id = DEINT_ID_INT0;
160  } else {
161  int flavor, sub_packet_h, coded_framesize, sub_packet_size;
162  int codecdata_length;
163  unsigned bytes_per_minute;
164  /* old version (4) */
165  avio_skip(pb, 2); /* unused */
166  avio_rb32(pb); /* .ra4 */
167  avio_rb32(pb); /* data size */
168  avio_rb16(pb); /* version2 */
169  avio_rb32(pb); /* header size */
170  flavor= avio_rb16(pb); /* add codec info / flavor */
171  coded_framesize = avio_rb32(pb); /* coded frame size */
172  if (coded_framesize < 0)
173  return AVERROR_INVALIDDATA;
174  ast->coded_framesize = coded_framesize;
175 
176  avio_rb32(pb); /* ??? */
177  bytes_per_minute = avio_rb32(pb);
178  if (version == 4) {
179  if (bytes_per_minute)
180  st->codecpar->bit_rate = 8LL * bytes_per_minute / 60;
181  }
182  avio_rb32(pb); /* ??? */
183  ast->sub_packet_h = sub_packet_h = avio_rb16(pb); /* 1 */
184  st->codecpar->block_align= avio_rb16(pb); /* frame size */
185  ast->sub_packet_size = sub_packet_size = avio_rb16(pb); /* sub packet size */
186  avio_rb16(pb); /* ??? */
187  if (version == 5) {
188  avio_rb16(pb); avio_rb16(pb); avio_rb16(pb);
189  }
190  st->codecpar->sample_rate = avio_rb16(pb);
191  avio_rb32(pb);
192  st->codecpar->channels = avio_rb16(pb);
193  if (version == 5) {
194  ast->deint_id = avio_rl32(pb);
195  avio_read(pb, buf, 4);
196  buf[4] = 0;
197  } else {
198  AV_WL32(buf, 0);
199  get_str8(pb, buf, sizeof(buf)); /* desc */
200  ast->deint_id = AV_RL32(buf);
201  get_str8(pb, buf, sizeof(buf)); /* desc */
202  }
204  st->codecpar->codec_tag = AV_RL32(buf);
206  st->codecpar->codec_tag);
207 
208  switch (st->codecpar->codec_id) {
209  case AV_CODEC_ID_AC3:
211  break;
212  case AV_CODEC_ID_RA_288:
213  st->codecpar->extradata_size= 0;
214  av_freep(&st->codecpar->extradata);
216  st->codecpar->block_align = coded_framesize;
217  break;
218  case AV_CODEC_ID_COOK:
220  case AV_CODEC_ID_ATRAC3:
221  case AV_CODEC_ID_SIPR:
222  if (read_all) {
223  codecdata_length = 0;
224  } else {
225  avio_rb16(pb); avio_r8(pb);
226  if (version == 5)
227  avio_r8(pb);
228  codecdata_length = avio_rb32(pb);
229  if((unsigned)codecdata_length > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE){
230  av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
231  return -1;
232  }
233  }
234 
236  if (st->codecpar->codec_id == AV_CODEC_ID_SIPR) {
237  if (flavor > 3) {
238  av_log(s, AV_LOG_ERROR, "bad SIPR file flavor %d\n",
239  flavor);
240  return -1;
241  }
242  st->codecpar->block_align = ff_sipr_subpk_size[flavor];
244  } else {
245  if(sub_packet_size <= 0){
246  av_log(s, AV_LOG_ERROR, "sub_packet_size is invalid\n");
247  return -1;
248  }
250  }
251  if ((ret = rm_read_extradata(s, pb, st->codecpar, codecdata_length)) < 0)
252  return ret;
253 
254  break;
255  case AV_CODEC_ID_AAC:
256  avio_rb16(pb); avio_r8(pb);
257  if (version == 5)
258  avio_r8(pb);
259  codecdata_length = avio_rb32(pb);
260  if((unsigned)codecdata_length > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE){
261  av_log(s, AV_LOG_ERROR, "codecdata_length too large\n");
262  return -1;
263  }
264  if (codecdata_length >= 1) {
265  avio_r8(pb);
266  if ((ret = rm_read_extradata(s, pb, st->codecpar, codecdata_length - 1)) < 0)
267  return ret;
268  }
269  break;
270  }
271  switch (ast->deint_id) {
272  case DEINT_ID_INT4:
273  if (ast->coded_framesize > ast->audio_framesize ||
274  sub_packet_h <= 1 ||
275  ast->coded_framesize * (uint64_t)sub_packet_h > (2 + (sub_packet_h & 1)) * ast->audio_framesize)
276  return AVERROR_INVALIDDATA;
277  if (ast->coded_framesize * (uint64_t)sub_packet_h != 2*ast->audio_framesize) {
278  avpriv_request_sample(s, "mismatching interleaver parameters");
279  return AVERROR_INVALIDDATA;
280  }
281  break;
282  case DEINT_ID_GENR:
283  if (ast->sub_packet_size <= 0 ||
284  ast->sub_packet_size > ast->audio_framesize)
285  return AVERROR_INVALIDDATA;
286  if (ast->audio_framesize % ast->sub_packet_size)
287  return AVERROR_INVALIDDATA;
288  break;
289  case DEINT_ID_SIPR:
290  case DEINT_ID_INT0:
291  case DEINT_ID_VBRS:
292  case DEINT_ID_VBRF:
293  break;
294  default:
295  av_log(s, AV_LOG_ERROR ,"Unknown interleaver %"PRIX32"\n", ast->deint_id);
296  return AVERROR_INVALIDDATA;
297  }
298  if (ast->deint_id == DEINT_ID_INT4 ||
299  ast->deint_id == DEINT_ID_GENR ||
300  ast->deint_id == DEINT_ID_SIPR) {
301  if (st->codecpar->block_align <= 0 ||
302  ast->audio_framesize * (uint64_t)sub_packet_h > (unsigned)INT_MAX ||
303  ast->audio_framesize * sub_packet_h < st->codecpar->block_align)
304  return AVERROR_INVALIDDATA;
305  if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0)
306  return AVERROR(ENOMEM);
307  }
308 
309  if (read_all) {
310  avio_r8(pb);
311  avio_r8(pb);
312  avio_r8(pb);
313  rm_read_metadata(s, pb, 0);
314  }
315  }
316  return 0;
317 }
318 
320  AVStream *st, RMStream *rst,
321  unsigned int codec_data_size, const uint8_t *mime)
322 {
323  unsigned int v;
324  int size;
325  int64_t codec_pos;
326  int ret;
327 
328  if (codec_data_size > INT_MAX)
329  return AVERROR_INVALIDDATA;
330  if (codec_data_size == 0)
331  return 0;
332 
333  avpriv_set_pts_info(st, 64, 1, 1000);
334  codec_pos = avio_tell(pb);
335  v = avio_rb32(pb);
336 
337  if (v == MKTAG(0xfd, 'a', 'r', '.')) {
338  /* ra type header */
339  if (rm_read_audio_stream_info(s, pb, st, rst, 0))
340  return -1;
341  } else if (v == MKBETAG('L', 'S', 'D', ':')) {
342  avio_seek(pb, -4, SEEK_CUR);
343  if ((ret = rm_read_extradata(s, pb, st->codecpar, codec_data_size)) < 0)
344  return ret;
345 
349  st->codecpar->codec_tag);
350  } else if(mime && !strcmp(mime, "logical-fileinfo")){
351  int stream_count, rule_count, property_count, i;
352  ff_free_stream(s, st);
353  if (avio_rb16(pb) != 0) {
354  av_log(s, AV_LOG_WARNING, "Unsupported version\n");
355  goto skip;
356  }
357  stream_count = avio_rb16(pb);
358  avio_skip(pb, 6*stream_count);
359  rule_count = avio_rb16(pb);
360  avio_skip(pb, 2*rule_count);
361  property_count = avio_rb16(pb);
362  for(i=0; i<property_count; i++){
363  uint8_t name[128], val[128];
364  avio_rb32(pb);
365  if (avio_rb16(pb) != 0) {
366  av_log(s, AV_LOG_WARNING, "Unsupported Name value property version\n");
367  goto skip; //FIXME skip just this one
368  }
369  get_str8(pb, name, sizeof(name));
370  switch(avio_rb32(pb)) {
371  case 2: get_strl(pb, val, sizeof(val), avio_rb16(pb));
372  av_dict_set(&s->metadata, name, val, 0);
373  break;
374  default: avio_skip(pb, avio_rb16(pb));
375  }
376  }
377  } else {
378  int fps;
379  if (avio_rl32(pb) != MKTAG('V', 'I', 'D', 'O')) {
380  fail1:
381  av_log(s, AV_LOG_WARNING, "Unsupported stream type %08x\n", v);
382  goto skip;
383  }
384  st->codecpar->codec_tag = avio_rl32(pb);
386  st->codecpar->codec_tag);
387  av_log(s, AV_LOG_TRACE, "%"PRIX32" %X\n",
388  st->codecpar->codec_tag, MKTAG('R', 'V', '2', '0'));
389  if (st->codecpar->codec_id == AV_CODEC_ID_NONE)
390  goto fail1;
391  st->codecpar->width = avio_rb16(pb);
392  st->codecpar->height = avio_rb16(pb);
393  avio_skip(pb, 2); // looks like bits per sample
394  avio_skip(pb, 4); // always zero?
397  fps = avio_rb32(pb);
398 
399  if ((ret = rm_read_extradata(s, pb, st->codecpar, codec_data_size - (avio_tell(pb) - codec_pos))) < 0)
400  return ret;
401 
402  if (fps > 0) {
404  0x10000, fps, (1 << 30) - 1);
405 #if FF_API_R_FRAME_RATE
406  st->r_frame_rate = st->avg_frame_rate;
407 #endif
408  } else if (s->error_recognition & AV_EF_EXPLODE) {
409  av_log(s, AV_LOG_ERROR, "Invalid framerate\n");
410  return AVERROR_INVALIDDATA;
411  }
412  }
413 
414 skip:
415  /* skip codec info */
416  size = avio_tell(pb) - codec_pos;
417  if (codec_data_size >= size) {
418  avio_skip(pb, codec_data_size - size);
419  } else {
420  av_log(s, AV_LOG_WARNING, "codec_data_size %u < size %d\n", codec_data_size, size);
421  }
422 
423  return 0;
424 }
425 
426 /** this function assumes that the demuxer has already seeked to the start
427  * of the INDX chunk, and will bail out if not. */
429 {
430  AVIOContext *pb = s->pb;
431  unsigned int size, n_pkts, str_id, next_off, n, pos, pts;
432  AVStream *st;
433 
434  do {
435  if (avio_rl32(pb) != MKTAG('I','N','D','X'))
436  return -1;
437  size = avio_rb32(pb);
438  if (size < 20)
439  return -1;
440  avio_skip(pb, 2);
441  n_pkts = avio_rb32(pb);
442  str_id = avio_rb16(pb);
443  next_off = avio_rb32(pb);
444  for (n = 0; n < s->nb_streams; n++)
445  if (s->streams[n]->id == str_id) {
446  st = s->streams[n];
447  break;
448  }
449  if (n == s->nb_streams) {
451  "Invalid stream index %d for index at pos %"PRId64"\n",
452  str_id, avio_tell(pb));
453  goto skip;
454  } else if ((avio_size(pb) - avio_tell(pb)) / 14 < n_pkts) {
456  "Nr. of packets in packet index for stream index %d "
457  "exceeds filesize (%"PRId64" at %"PRId64" = %"PRId64")\n",
458  str_id, avio_size(pb), avio_tell(pb),
459  (avio_size(pb) - avio_tell(pb)) / 14);
460  goto skip;
461  }
462 
463  for (n = 0; n < n_pkts; n++) {
464  if (avio_feof(pb))
465  return AVERROR_INVALIDDATA;
466  avio_skip(pb, 2);
467  pts = avio_rb32(pb);
468  pos = avio_rb32(pb);
469  avio_skip(pb, 4); /* packet no. */
470 
472  }
473 
474 skip:
475  if (next_off && avio_tell(pb) < next_off &&
476  avio_seek(pb, next_off, SEEK_SET) < 0) {
478  "Non-linear index detected, not supported\n");
479  return -1;
480  }
481  } while (next_off);
482 
483  return 0;
484 }
485 
487 {
488  RMDemuxContext *rm = s->priv_data;
489  AVStream *st;
490 
491  rm->old_format = 1;
492  st = avformat_new_stream(s, NULL);
493  if (!st)
494  return -1;
496  if (!st->priv_data)
497  return AVERROR(ENOMEM);
498  return rm_read_audio_stream_info(s, s->pb, st, st->priv_data, 1);
499 }
500 
502  AVStream *st, char *mime)
503 {
504  int number_of_streams = avio_rb16(pb);
505  int number_of_mdpr;
506  int i, ret;
507  unsigned size2;
508  for (i = 0; i<number_of_streams; i++)
509  avio_rb16(pb);
510  number_of_mdpr = avio_rb16(pb);
511  if (number_of_mdpr != 1) {
512  avpriv_request_sample(s, "MLTI with multiple (%d) MDPR", number_of_mdpr);
513  }
514  for (i = 0; i < number_of_mdpr; i++) {
515  AVStream *st2;
516  if (i > 0) {
517  st2 = avformat_new_stream(s, NULL);
518  if (!st2) {
519  ret = AVERROR(ENOMEM);
520  return ret;
521  }
522  st2->id = st->id + (i<<16);
523  st2->codecpar->bit_rate = st->codecpar->bit_rate;
524  st2->start_time = st->start_time;
525  st2->duration = st->duration;
528  if (!st2->priv_data)
529  return AVERROR(ENOMEM);
530  } else
531  st2 = st;
532 
533  size2 = avio_rb32(pb);
534  ret = ff_rm_read_mdpr_codecdata(s, s->pb, st2, st2->priv_data,
535  size2, NULL);
536  if (ret < 0)
537  return ret;
538  }
539  return 0;
540 }
541 
543 {
544  RMDemuxContext *rm = s->priv_data;
545  AVStream *st;
546  AVIOContext *pb = s->pb;
547  unsigned int tag;
548  int tag_size;
549  unsigned int start_time, duration;
550  unsigned int data_off = 0, indx_off = 0;
551  char buf[128], mime[128];
552  int flags = 0;
553  int ret;
554  unsigned size, v;
555  int64_t codec_pos;
556 
557  tag = avio_rl32(pb);
558  if (tag == MKTAG('.', 'r', 'a', 0xfd)) {
559  /* very old .ra format */
560  return rm_read_header_old(s);
561  } else if (tag != MKTAG('.', 'R', 'M', 'F')) {
562  return AVERROR(EIO);
563  }
564 
565  tag_size = avio_rb32(pb);
566  avio_skip(pb, tag_size - 8);
567 
568  for(;;) {
569  if (avio_feof(pb))
570  return AVERROR_INVALIDDATA;
571  tag = avio_rl32(pb);
572  tag_size = avio_rb32(pb);
573  avio_rb16(pb);
574  av_log(s, AV_LOG_TRACE, "tag=%s size=%d\n",
575  av_fourcc2str(tag), tag_size);
576  if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A'))
577  return AVERROR_INVALIDDATA;
578  switch(tag) {
579  case MKTAG('P', 'R', 'O', 'P'):
580  /* file header */
581  avio_rb32(pb); /* max bit rate */
582  avio_rb32(pb); /* avg bit rate */
583  avio_rb32(pb); /* max packet size */
584  avio_rb32(pb); /* avg packet size */
585  avio_rb32(pb); /* nb packets */
586  duration = avio_rb32(pb); /* duration */
587  s->duration = av_rescale(duration, AV_TIME_BASE, 1000);
588  avio_rb32(pb); /* preroll */
589  indx_off = avio_rb32(pb); /* index offset */
590  data_off = avio_rb32(pb); /* data offset */
591  avio_rb16(pb); /* nb streams */
592  flags = avio_rb16(pb); /* flags */
593  break;
594  case MKTAG('C', 'O', 'N', 'T'):
595  rm_read_metadata(s, pb, 1);
596  break;
597  case MKTAG('M', 'D', 'P', 'R'):
598  st = avformat_new_stream(s, NULL);
599  if (!st)
600  return AVERROR(ENOMEM);
601  st->id = avio_rb16(pb);
602  avio_rb32(pb); /* max bit rate */
603  st->codecpar->bit_rate = avio_rb32(pb); /* bit rate */
604  avio_rb32(pb); /* max packet size */
605  avio_rb32(pb); /* avg packet size */
606  start_time = avio_rb32(pb); /* start time */
607  avio_rb32(pb); /* preroll */
608  duration = avio_rb32(pb); /* duration */
609  st->start_time = start_time;
610  st->duration = duration;
611  if(duration>0)
612  s->duration = AV_NOPTS_VALUE;
613  get_str8(pb, buf, sizeof(buf)); /* desc */
614  get_str8(pb, mime, sizeof(mime)); /* mimetype */
617  if (!st->priv_data)
618  return AVERROR(ENOMEM);
619 
620  size = avio_rb32(pb);
621  codec_pos = avio_tell(pb);
622 
623  ffio_ensure_seekback(pb, 4);
624  v = avio_rb32(pb);
625  if (v == MKBETAG('M', 'L', 'T', 'I')) {
626  ret = rm_read_multi(s, s->pb, st, mime);
627  if (ret < 0)
628  return ret;
629  avio_seek(pb, codec_pos + size, SEEK_SET);
630  } else {
631  avio_skip(pb, -4);
632  ret = ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data,
633  size, mime);
634  if (ret < 0)
635  return ret;
636  }
637 
638  break;
639  case MKTAG('D', 'A', 'T', 'A'):
640  goto header_end;
641  default:
642  /* unknown tag: skip it */
643  avio_skip(pb, tag_size - 10);
644  break;
645  }
646  }
647  header_end:
648  rm->nb_packets = avio_rb32(pb); /* number of packets */
649  if (!rm->nb_packets && (flags & 4))
650  rm->nb_packets = 3600 * 25;
651  avio_rb32(pb); /* next data header */
652 
653  if (!data_off)
654  data_off = avio_tell(pb) - 18;
655  if (indx_off && (pb->seekable & AVIO_SEEKABLE_NORMAL) &&
656  !(s->flags & AVFMT_FLAG_IGNIDX) &&
657  avio_seek(pb, indx_off, SEEK_SET) >= 0) {
658  rm_read_index(s);
659  avio_seek(pb, data_off + 18, SEEK_SET);
660  }
661 
662  return 0;
663 }
664 
665 static int get_num(AVIOContext *pb, int *len)
666 {
667  int n, n1;
668 
669  n = avio_rb16(pb);
670  (*len)-=2;
671  n &= 0x7FFF;
672  if (n >= 0x4000) {
673  return n - 0x4000;
674  } else {
675  n1 = avio_rb16(pb);
676  (*len)-=2;
677  return (n << 16) | n1;
678  }
679 }
680 
681 /* multiple of 20 bytes for ra144 (ugly) */
682 #define RAW_PACKET_SIZE 1000
683 
684 static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){
685  RMDemuxContext *rm = s->priv_data;
686  AVIOContext *pb = s->pb;
687  AVStream *st;
688  uint32_t state=0xFFFFFFFF;
689 
690  while(!avio_feof(pb)){
691  int len, num, i;
692  int mlti_id;
693  *pos= avio_tell(pb) - 3;
694  if(rm->remaining_len > 0){
695  num= rm->current_stream;
696  mlti_id = 0;
697  len= rm->remaining_len;
698  *timestamp = AV_NOPTS_VALUE;
699  *flags= 0;
700  }else{
701  state= (state<<8) + avio_r8(pb);
702 
703  if(state == MKBETAG('I', 'N', 'D', 'X')){
704  int n_pkts;
705  int64_t expected_len;
706  len = avio_rb32(pb);
707  avio_skip(pb, 2);
708  n_pkts = avio_rb32(pb);
709  expected_len = 20 + n_pkts * 14LL;
710 
711  if (len == 20 && expected_len <= INT_MAX)
712  /* some files don't add index entries to chunk size... */
713  len = expected_len;
714  else if (len != expected_len)
716  "Index size %d (%d pkts) is wrong, should be %"PRId64".\n",
717  len, n_pkts, expected_len);
718  if(len < 14)
719  continue;
720  len -= 14; // we already read part of the index header
721  goto skip;
722  } else if (state == MKBETAG('D','A','T','A')) {
724  "DATA tag in middle of chunk, file may be broken.\n");
725  }
726 
727  if(state > (unsigned)0xFFFF || state <= 12)
728  continue;
729  len=state - 12;
730  state= 0xFFFFFFFF;
731 
732  num = avio_rb16(pb);
733  *timestamp = avio_rb32(pb);
734  mlti_id = (avio_r8(pb) >> 1) - 1;
735  mlti_id = FFMAX(mlti_id, 0) << 16;
736  *flags = avio_r8(pb); /* flags */
737  }
738  for(i=0;i<s->nb_streams;i++) {
739  st = s->streams[i];
740  if (mlti_id + num == st->id)
741  break;
742  }
743  if (i == s->nb_streams) {
744 skip:
745  /* skip packet if unknown number */
746  avio_skip(pb, len);
747  rm->remaining_len = 0;
748  continue;
749  }
750  *stream_index= i;
751 
752  return len;
753  }
754  return -1;
755 }
756 
758  RMDemuxContext *rm, RMStream *vst,
759  AVPacket *pkt, int len, int *pseq,
760  int64_t *timestamp)
761 {
762  int hdr;
763  int seq = 0, pic_num = 0, len2 = 0, pos = 0; //init to silence compiler warning
764  int type;
765  int ret;
766 
767  hdr = avio_r8(pb); len--;
768  type = hdr >> 6;
769 
770  if(type != 3){ // not frame as a part of packet
771  seq = avio_r8(pb); len--;
772  }
773  if(type != 1){ // not whole frame
774  len2 = get_num(pb, &len);
775  pos = get_num(pb, &len);
776  pic_num = avio_r8(pb); len--;
777  }
778  if(len<0) {
779  av_log(s, AV_LOG_ERROR, "Insufficient data\n");
780  return -1;
781  }
782  rm->remaining_len = len;
783  if(type&1){ // frame, not slice
784  if(type == 3){ // frame as a part of packet
785  len= len2;
786  *timestamp = pos;
787  }
788  if(rm->remaining_len < len) {
789  av_log(s, AV_LOG_ERROR, "Insufficient remaining len\n");
790  return -1;
791  }
792  rm->remaining_len -= len;
793  if ((ret = av_new_packet(pkt, len + 9)) < 0)
794  return ret;
795  pkt->data[0] = 0;
796  AV_WL32(pkt->data + 1, 1);
797  AV_WL32(pkt->data + 5, 0);
798  if ((ret = avio_read(pb, pkt->data + 9, len)) != len) {
800  av_log(s, AV_LOG_ERROR, "Failed to read %d bytes\n", len);
801  return ret < 0 ? ret : AVERROR(EIO);
802  }
803  return 0;
804  }
805  //now we have to deal with single slice
806 
807  *pseq = seq;
808  if((seq & 0x7F) == 1 || vst->curpic_num != pic_num){
809  if (len2 > ffio_limit(pb, len2)) {
810  av_log(s, AV_LOG_ERROR, "Impossibly sized packet\n");
811  return AVERROR_INVALIDDATA;
812  }
813  vst->slices = ((hdr & 0x3F) << 1) + 1;
814  vst->videobufsize = len2 + 8*vst->slices + 1;
815  av_packet_unref(&vst->pkt); //FIXME this should be output.
816  if ((ret = av_new_packet(&vst->pkt, vst->videobufsize)) < 0)
817  return ret;
818  vst->videobufpos = 8*vst->slices + 1;
819  vst->cur_slice = 0;
820  vst->curpic_num = pic_num;
821  vst->pktpos = avio_tell(pb);
822  }
823  if(type == 2)
824  len = FFMIN(len, pos);
825 
826  if(++vst->cur_slice > vst->slices) {
827  av_log(s, AV_LOG_ERROR, "cur slice %d, too large\n", vst->cur_slice);
828  return 1;
829  }
830  if(!vst->pkt.data)
831  return AVERROR(ENOMEM);
832  AV_WL32(vst->pkt.data - 7 + 8*vst->cur_slice, 1);
833  AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1);
834  if(vst->videobufpos + len > vst->videobufsize) {
835  av_log(s, AV_LOG_ERROR, "outside videobufsize\n");
836  return 1;
837  }
838  if (avio_read(pb, vst->pkt.data + vst->videobufpos, len) != len)
839  return AVERROR(EIO);
840  vst->videobufpos += len;
841  rm->remaining_len-= len;
842 
843  if (type == 2 || vst->videobufpos == vst->videobufsize) {
844  vst->pkt.data[0] = vst->cur_slice-1;
845  av_packet_move_ref(pkt, &vst->pkt);
846  if(vst->slices != vst->cur_slice) //FIXME find out how to set slices correct from the begin
847  memmove(pkt->data + 1 + 8*vst->cur_slice, pkt->data + 1 + 8*vst->slices,
848  vst->videobufpos - 1 - 8*vst->slices);
849  av_shrink_packet(pkt, vst->videobufpos + 8*(vst->cur_slice - vst->slices));
851  pkt->pos = vst->pktpos;
852  vst->slices = 0;
853  return 0;
854  }
855 
856  return 1;
857 }
858 
859 static inline void
861 {
862  uint8_t *ptr;
863  int j;
864 
865  if (st->codecpar->codec_id == AV_CODEC_ID_AC3) {
866  ptr = pkt->data;
867  for (j=0;j<pkt->size;j+=2) {
868  FFSWAP(int, ptr[0], ptr[1]);
869  ptr += 2;
870  }
871  }
872 }
873 
874 static int readfull(AVFormatContext *s, AVIOContext *pb, uint8_t *dst, int n) {
875  int ret = avio_read(pb, dst, n);
876  if (ret != n) {
877  if (ret >= 0) memset(dst + ret, 0, n - ret);
878  else memset(dst , 0, n);
879  av_log(s, AV_LOG_ERROR, "Failed to fully read block\n");
880  }
881  return ret;
882 }
883 
884 int
886  AVStream *st, RMStream *ast, int len, AVPacket *pkt,
887  int *seq, int flags, int64_t timestamp)
888 {
889  RMDemuxContext *rm = s->priv_data;
890  int ret;
891 
892  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
893  rm->current_stream= st->id;
894  ret = rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, &timestamp);
895  if(ret)
896  return ret < 0 ? ret : -1; //got partial frame or error
897  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
898  if ((ast->deint_id == DEINT_ID_GENR) ||
899  (ast->deint_id == DEINT_ID_INT4) ||
900  (ast->deint_id == DEINT_ID_SIPR)) {
901  int x;
902  int sps = ast->sub_packet_size;
903  int cfs = ast->coded_framesize;
904  int h = ast->sub_packet_h;
905  int y = ast->sub_packet_cnt;
906  int w = ast->audio_framesize;
907 
908  if (flags & 2)
909  y = ast->sub_packet_cnt = 0;
910  if (!y)
911  ast->audiotimestamp = timestamp;
912 
913  switch (ast->deint_id) {
914  case DEINT_ID_INT4:
915  for (x = 0; x < h/2; x++)
916  readfull(s, pb, ast->pkt.data+x*2*w+y*cfs, cfs);
917  break;
918  case DEINT_ID_GENR:
919  for (x = 0; x < w/sps; x++)
920  readfull(s, pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps);
921  break;
922  case DEINT_ID_SIPR:
923  readfull(s, pb, ast->pkt.data + y * w, w);
924  break;
925  }
926 
927  if (++(ast->sub_packet_cnt) < h)
928  return -1;
929  if (ast->deint_id == DEINT_ID_SIPR)
931 
932  ast->sub_packet_cnt = 0;
933  rm->audio_stream_num = st->index;
934  if (st->codecpar->block_align <= 0) {
935  av_log(s, AV_LOG_ERROR, "Invalid block alignment %d\n", st->codecpar->block_align);
936  return AVERROR_INVALIDDATA;
937  }
938  rm->audio_pkt_cnt = h * w / st->codecpar->block_align;
939  } else if ((ast->deint_id == DEINT_ID_VBRF) ||
940  (ast->deint_id == DEINT_ID_VBRS)) {
941  int x;
942  rm->audio_stream_num = st->index;
943  ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4;
944  if (ast->sub_packet_cnt) {
945  for (x = 0; x < ast->sub_packet_cnt; x++)
946  ast->sub_packet_lengths[x] = avio_rb16(pb);
947  rm->audio_pkt_cnt = ast->sub_packet_cnt;
948  ast->audiotimestamp = timestamp;
949  } else
950  return -1;
951  } else {
952  ret = av_get_packet(pb, pkt, len);
953  if (ret < 0)
954  return ret;
955  rm_ac3_swap_bytes(st, pkt);
956  }
957  } else {
958  ret = av_get_packet(pb, pkt, len);
959  if (ret < 0)
960  return ret;
961  }
962 
963  pkt->stream_index = st->index;
964 
965  pkt->pts = timestamp;
966  if (flags & 2)
968 
969  return st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO ? rm->audio_pkt_cnt : 0;
970 }
971 
972 int
974  AVStream *st, RMStream *ast, AVPacket *pkt)
975 {
976  RMDemuxContext *rm = s->priv_data;
977  int ret;
978 
979  av_assert0 (rm->audio_pkt_cnt > 0);
980 
981  if (ast->deint_id == DEINT_ID_VBRF ||
982  ast->deint_id == DEINT_ID_VBRS) {
984  if (ret < 0)
985  return ret;
986  } else {
988  if (ret < 0)
989  return ret;
990  memcpy(pkt->data, ast->pkt.data + st->codecpar->block_align * //FIXME avoid this
992  st->codecpar->block_align);
993  }
994  rm->audio_pkt_cnt--;
995  if ((pkt->pts = ast->audiotimestamp) != AV_NOPTS_VALUE) {
998  } else
999  pkt->flags = 0;
1000  pkt->stream_index = st->index;
1001 
1002  return rm->audio_pkt_cnt;
1003 }
1004 
1006 {
1007  RMDemuxContext *rm = s->priv_data;
1008  AVStream *st = NULL; // init to silence compiler warning
1009  int i, res, seq = 1;
1010  int64_t timestamp, pos, len;
1011  int flags;
1012 
1013  for (;;) {
1014  if (rm->audio_pkt_cnt) {
1015  // If there are queued audio packet return them first
1016  st = s->streams[rm->audio_stream_num];
1017  res = ff_rm_retrieve_cache(s, s->pb, st, st->priv_data, pkt);
1018  if(res < 0)
1019  return res;
1020  flags = 0;
1021  } else {
1022  if (rm->old_format) {
1023  RMStream *ast;
1024 
1025  st = s->streams[0];
1026  ast = st->priv_data;
1027  timestamp = AV_NOPTS_VALUE;
1028  len = !ast->audio_framesize ? RAW_PACKET_SIZE :
1029  ast->coded_framesize * (int64_t)ast->sub_packet_h / 2;
1030  if (len > INT_MAX)
1031  return AVERROR_INVALIDDATA;
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 (avio_feof(s->pb))
1041  return AVERROR_EOF;
1042  if (len <= 0)
1043  return AVERROR(EIO);
1044 
1045  res = ff_rm_parse_packet (s, s->pb, st, st->priv_data, len, pkt,
1046  &seq, flags, timestamp);
1047  if (res < -1)
1048  return res;
1049  if((flags&2) && (seq&0x7F) == 1)
1050  av_add_index_entry(st, pos, timestamp, 0, 0, AVINDEX_KEYFRAME);
1051  if (res)
1052  continue;
1053  }
1054 
1055  if( (st->discard >= AVDISCARD_NONKEY && !(flags&2))
1056  || st->discard >= AVDISCARD_ALL){
1058  } else
1059  break;
1060  }
1061 
1062  return 0;
1063 }
1064 
1066 {
1067  int i;
1068 
1069  for (i=0;i<s->nb_streams;i++)
1070  ff_rm_free_rmstream(s->streams[i]->priv_data);
1071 
1072  return 0;
1073 }
1074 
1075 static int rm_probe(const AVProbeData *p)
1076 {
1077  /* check file header */
1078  if ((p->buf[0] == '.' && p->buf[1] == 'R' &&
1079  p->buf[2] == 'M' && p->buf[3] == 'F' &&
1080  p->buf[4] == 0 && p->buf[5] == 0) ||
1081  (p->buf[0] == '.' && p->buf[1] == 'r' &&
1082  p->buf[2] == 'a' && p->buf[3] == 0xfd))
1083  return AVPROBE_SCORE_MAX;
1084  else
1085  return 0;
1086 }
1087 
1088 static int64_t rm_read_dts(AVFormatContext *s, int stream_index,
1089  int64_t *ppos, int64_t pos_limit)
1090 {
1091  RMDemuxContext *rm = s->priv_data;
1092  int64_t pos, dts;
1093  int stream_index2, flags, len, h;
1094 
1095  pos = *ppos;
1096 
1097  if(rm->old_format)
1098  return AV_NOPTS_VALUE;
1099 
1100  if (avio_seek(s->pb, pos, SEEK_SET) < 0)
1101  return AV_NOPTS_VALUE;
1102 
1103  rm->remaining_len=0;
1104  for(;;){
1105  int seq=1;
1106  AVStream *st;
1107 
1108  len = rm_sync(s, &dts, &flags, &stream_index2, &pos);
1109  if(len<0)
1110  return AV_NOPTS_VALUE;
1111 
1112  st = s->streams[stream_index2];
1113  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
1114  h= avio_r8(s->pb); len--;
1115  if(!(h & 0x40)){
1116  seq = avio_r8(s->pb); len--;
1117  }
1118  }
1119 
1120  if((flags&2) && (seq&0x7F) == 1){
1121  av_log(s, AV_LOG_TRACE, "%d %d-%d %"PRId64" %d\n",
1122  flags, stream_index2, stream_index, dts, seq);
1123  av_add_index_entry(st, pos, dts, 0, 0, AVINDEX_KEYFRAME);
1124  if(stream_index2 == stream_index)
1125  break;
1126  }
1127 
1128  avio_skip(s->pb, len);
1129  }
1130  *ppos = pos;
1131  return dts;
1132 }
1133 
1134 static int rm_read_seek(AVFormatContext *s, int stream_index,
1135  int64_t pts, int flags)
1136 {
1137  RMDemuxContext *rm = s->priv_data;
1138 
1139  if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0)
1140  return -1;
1141  rm->audio_pkt_cnt = 0;
1142  return 0;
1143 }
1144 
1145 
1147  .name = "rm",
1148  .long_name = NULL_IF_CONFIG_SMALL("RealMedia"),
1149  .priv_data_size = sizeof(RMDemuxContext),
1150  .flags_internal = FF_FMT_INIT_CLEANUP,
1151  .read_probe = rm_probe,
1157 };
1158 
1160  .name = "rdt",
1161  .long_name = NULL_IF_CONFIG_SMALL("RDT demuxer"),
1162  .priv_data_size = sizeof(RMDemuxContext),
1164  .flags = AVFMT_NOFILE,
1165 };
1166 
1167 static int ivr_probe(const AVProbeData *p)
1168 {
1169  if (memcmp(p->buf, ".R1M\x0\x1\x1", 7) &&
1170  memcmp(p->buf, ".REC", 4))
1171  return 0;
1172 
1173  return AVPROBE_SCORE_MAX;
1174 }
1175 
1177 {
1178  unsigned tag, type, len, tlen, value;
1179  int i, j, n, count, nb_streams = 0, ret;
1180  uint8_t key[256], val[256];
1181  AVIOContext *pb = s->pb;
1182  AVStream *st;
1183  int64_t pos, offset=0, temp;
1184 
1185  pos = avio_tell(pb);
1186  tag = avio_rl32(pb);
1187  if (tag == MKTAG('.','R','1','M')) {
1188  if (avio_rb16(pb) != 1)
1189  return AVERROR_INVALIDDATA;
1190  if (avio_r8(pb) != 1)
1191  return AVERROR_INVALIDDATA;
1192  len = avio_rb32(pb);
1193  avio_skip(pb, len);
1194  avio_skip(pb, 5);
1195  temp = avio_rb64(pb);
1196  while (!avio_feof(pb) && temp) {
1197  offset = temp;
1198  temp = avio_rb64(pb);
1199  }
1200  if (offset <= 0)
1201  return AVERROR_INVALIDDATA;
1202  avio_skip(pb, offset - avio_tell(pb));
1203  if (avio_r8(pb) != 1)
1204  return AVERROR_INVALIDDATA;
1205  len = avio_rb32(pb);
1206  avio_skip(pb, len);
1207  if (avio_r8(pb) != 2)
1208  return AVERROR_INVALIDDATA;
1209  avio_skip(pb, 16);
1210  pos = avio_tell(pb);
1211  tag = avio_rl32(pb);
1212  }
1213 
1214  if (tag != MKTAG('.','R','E','C'))
1215  return AVERROR_INVALIDDATA;
1216 
1217  if (avio_r8(pb) != 0)
1218  return AVERROR_INVALIDDATA;
1219  count = avio_rb32(pb);
1220  for (i = 0; i < count; i++) {
1221  if (avio_feof(pb))
1222  return AVERROR_INVALIDDATA;
1223 
1224  type = avio_r8(pb);
1225  tlen = avio_rb32(pb);
1226  avio_get_str(pb, tlen, key, sizeof(key));
1227  len = avio_rb32(pb);
1228  if (type == 5) {
1229  avio_get_str(pb, len, val, sizeof(val));
1230  av_log(s, AV_LOG_DEBUG, "%s = '%s'\n", key, val);
1231  } else if (type == 4) {
1232  av_log(s, AV_LOG_DEBUG, "%s = '0x", key);
1233  for (j = 0; j < len; j++) {
1234  if (avio_feof(pb))
1235  return AVERROR_INVALIDDATA;
1236  av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb));
1237  }
1238  av_log(s, AV_LOG_DEBUG, "'\n");
1239  } else if (len == 4 && type == 3 && !strncmp(key, "StreamCount", tlen)) {
1240  nb_streams = value = avio_rb32(pb);
1241  } else if (len == 4 && type == 3) {
1242  value = avio_rb32(pb);
1243  av_log(s, AV_LOG_DEBUG, "%s = %d\n", key, value);
1244  } else {
1245  av_log(s, AV_LOG_DEBUG, "Skipping unsupported key: %s\n", key);
1246  avio_skip(pb, len);
1247  }
1248  }
1249 
1250  for (n = 0; n < nb_streams; n++) {
1251  if (!(st = avformat_new_stream(s, NULL)) ||
1252  !(st->priv_data = ff_rm_alloc_rmstream()))
1253  return AVERROR(ENOMEM);
1254 
1255  if (avio_r8(pb) != 1)
1256  return AVERROR_INVALIDDATA;
1257 
1258  count = avio_rb32(pb);
1259  for (i = 0; i < count; i++) {
1260  if (avio_feof(pb))
1261  return AVERROR_INVALIDDATA;
1262 
1263  type = avio_r8(pb);
1264  tlen = avio_rb32(pb);
1265  avio_get_str(pb, tlen, key, sizeof(key));
1266  len = avio_rb32(pb);
1267  if (type == 5) {
1268  avio_get_str(pb, len, val, sizeof(val));
1269  av_log(s, AV_LOG_DEBUG, "%s = '%s'\n", key, val);
1270  } else if (type == 4 && !strncmp(key, "OpaqueData", tlen)) {
1271  ret = ffio_ensure_seekback(pb, 4);
1272  if (ret < 0)
1273  return ret;
1274  if (avio_rb32(pb) == MKBETAG('M', 'L', 'T', 'I')) {
1275  ret = rm_read_multi(s, pb, st, NULL);
1276  } else {
1277  if (avio_feof(pb))
1278  return AVERROR_INVALIDDATA;
1279  avio_seek(pb, -4, SEEK_CUR);
1280  ret = ff_rm_read_mdpr_codecdata(s, pb, st, st->priv_data, len, NULL);
1281  }
1282 
1283  if (ret < 0)
1284  return ret;
1285  } else if (type == 4) {
1286  int j;
1287 
1288  av_log(s, AV_LOG_DEBUG, "%s = '0x", key);
1289  for (j = 0; j < len; j++) {
1290  if (avio_feof(pb))
1291  return AVERROR_INVALIDDATA;
1292  av_log(s, AV_LOG_DEBUG, "%X", avio_r8(pb));
1293  }
1294  av_log(s, AV_LOG_DEBUG, "'\n");
1295  } else if (len == 4 && type == 3 && !strncmp(key, "Duration", tlen)) {
1296  st->duration = avio_rb32(pb);
1297  } else if (len == 4 && type == 3) {
1298  value = avio_rb32(pb);
1299  av_log(s, AV_LOG_DEBUG, "%s = %d\n", key, value);
1300  } else {
1301  av_log(s, AV_LOG_DEBUG, "Skipping unsupported key: %s\n", key);
1302  avio_skip(pb, len);
1303  }
1304  }
1305  }
1306 
1307  if (avio_r8(pb) != 6)
1308  return AVERROR_INVALIDDATA;
1309  avio_skip(pb, 12);
1310  avio_seek(pb, avio_rb64(pb) + pos, SEEK_SET);
1311  if (avio_r8(pb) != 8)
1312  return AVERROR_INVALIDDATA;
1313  avio_skip(pb, 8);
1314 
1315  return 0;
1316 }
1317 
1319 {
1320  RMDemuxContext *rm = s->priv_data;
1321  int ret = AVERROR_EOF, opcode;
1322  AVIOContext *pb = s->pb;
1323  unsigned size, index;
1324  int64_t pos, pts;
1325 
1326  if (avio_feof(pb) || rm->data_end)
1327  return AVERROR_EOF;
1328 
1329  pos = avio_tell(pb);
1330 
1331  for (;;) {
1332  if (rm->audio_pkt_cnt) {
1333  // If there are queued audio packet return them first
1334  AVStream *st;
1335 
1336  st = s->streams[rm->audio_stream_num];
1337  ret = ff_rm_retrieve_cache(s, pb, st, st->priv_data, pkt);
1338  if (ret < 0) {
1339  return ret;
1340  }
1341  } else {
1342  if (rm->remaining_len) {
1343  avio_skip(pb, rm->remaining_len);
1344  rm->remaining_len = 0;
1345  }
1346 
1347  if (avio_feof(pb))
1348  return AVERROR_EOF;
1349 
1350  opcode = avio_r8(pb);
1351  if (opcode == 2) {
1352  AVStream *st;
1353  int seq = 1;
1354 
1355  pts = avio_rb32(pb);
1356  index = avio_rb16(pb);
1357  if (index >= s->nb_streams)
1358  return AVERROR_INVALIDDATA;
1359 
1360  avio_skip(pb, 4);
1361  size = avio_rb32(pb);
1362  avio_skip(pb, 4);
1363 
1364  if (size < 1 || size > INT_MAX/4) {
1365  av_log(s, AV_LOG_ERROR, "size %u is invalid\n", size);
1366  return AVERROR_INVALIDDATA;
1367  }
1368 
1369  st = s->streams[index];
1370  ret = ff_rm_parse_packet(s, pb, st, st->priv_data, size, pkt,
1371  &seq, 0, pts);
1372  if (ret < -1) {
1373  return ret;
1374  } else if (ret) {
1375  continue;
1376  }
1377 
1378  pkt->pos = pos;
1379  pkt->pts = pts;
1380  pkt->stream_index = index;
1381  } else if (opcode == 7) {
1382  pos = avio_rb64(pb);
1383  if (!pos) {
1384  rm->data_end = 1;
1385  return AVERROR_EOF;
1386  }
1387  } else {
1388  av_log(s, AV_LOG_ERROR, "Unsupported opcode=%d at %"PRIX64"\n", opcode, avio_tell(pb) - 1);
1389  return AVERROR(EIO);
1390  }
1391  }
1392 
1393  break;
1394  }
1395 
1396  return ret;
1397 }
1398 
1400  .name = "ivr",
1401  .long_name = NULL_IF_CONFIG_SMALL("IVR (Internet Video Recording)"),
1402  .priv_data_size = sizeof(RMDemuxContext),
1403  .flags_internal = FF_FMT_INIT_CLEANUP,
1404  .read_probe = ivr_probe,
1408  .extensions = "ivr",
1409 };
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:417
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AVCodecParameters::extradata
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
Definition: codec_par.h:74
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
rm_read_index
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:428
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: codec_id.h:426
FF_FMT_INIT_CLEANUP
#define FF_FMT_INIT_CLEANUP
For an AVInputFormat with this flag set read_close() needs to be called by the caller upon read_heade...
Definition: internal.h:48
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
avformat_new_stream
AVStream * avformat_new_stream(AVFormatContext *s, const AVCodec *c)
Add a new stream to a media file.
Definition: utils.c:724
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: codec_par.h:56
AV_WL32
#define AV_WL32(p, v)
Definition: intreadwrite.h:426
ff_get_extradata
int ff_get_extradata(AVFormatContext *s, AVCodecParameters *par, 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:469
ff_rm_reorder_sipr_data
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
AVCodecParameters
This struct describes the properties of an encoded stream.
Definition: codec_par.h:52
AVFMT_FLAG_IGNIDX
#define AVFMT_FLAG_IGNIDX
Ignore index.
Definition: avformat.h:1229
rm_read_extradata
static int rm_read_extradata(AVFormatContext *s, AVIOContext *pb, AVCodecParameters *par, unsigned size)
Definition: rmdec.c:82
AVStream::priv_data
void * priv_data
Definition: avformat.h:866
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVStream::discard
enum AVDiscard discard
Selects which packets can be discarded at will and do not need to be demuxed.
Definition: avformat.h:906
RMStream::deint_id
int32_t deint_id
Length of each subpacket.
Definition: rmdec.c:56
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:90
ff_free_stream
void ff_free_stream(AVFormatContext *s, AVStream *st)
Definition: utils.c:671
ff_rm_retrieve_cache
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:973
AV_CODEC_ID_RA_144
@ AV_CODEC_ID_RA_144
Definition: codec_id.h:410
rmsipr.h
index
fg index
Definition: ffmpeg_filter.c:168
w
uint8_t w
Definition: llviddspenc.c:38
AVPacket::data
uint8_t * data
Definition: packet.h:373
AVStream::avg_frame_rate
AVRational avg_frame_rate
Average framerate.
Definition: avformat.h:924
RMStream::videobufpos
int videobufpos
position for the next slice in the video buffer
Definition: rmdec.c:46
ff_rm_demuxer
const AVInputFormat ff_rm_demuxer
Definition: rmdec.c:1146
AVCodecParameters::codec_tag
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
Definition: codec_par.h:64
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
DEINT_ID_SIPR
#define DEINT_ID_SIPR
interleaving for Sipro
Definition: rmdec.c:39
RMDemuxContext::data_end
int data_end
Definition: rmdec.c:66
DEINT_ID_VBRS
#define DEINT_ID_VBRS
VBR case for AAC.
Definition: rmdec.c:41
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:338
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:425
RAW_PACKET_SIZE
#define RAW_PACKET_SIZE
Definition: rmdec.c:682
ff_seek_frame_binary
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: seek.c:282
AVINDEX_KEYFRAME
#define AVINDEX_KEYFRAME
Definition: avformat.h:797
state
static struct @319 state
AVPROBE_SCORE_MAX
#define AVPROBE_SCORE_MAX
maximum score
Definition: avformat.h:458
RMStream::videobufsize
int videobufsize
current assembled frame size
Definition: rmdec.c:45
AVCodecParameters::channels
int channels
Audio only.
Definition: codec_par.h:166
ffstream
static av_always_inline FFStream * ffstream(AVStream *st)
Definition: internal.h:429
readfull
static int readfull(AVFormatContext *s, AVIOContext *pb, uint8_t *dst, int n)
Definition: rmdec.c:874
read_seek
static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, int flags)
Definition: libcdio.c:149
av_shrink_packet
void av_shrink_packet(AVPacket *pkt, int size)
Reduce packet size, correctly zeroing padding.
Definition: avpacket.c:114
av_add_index_entry
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: seek.c:117
read_close
static av_cold int read_close(AVFormatContext *ctx)
Definition: libcdio.c:141
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:486
val
static double val(void *priv, double ch)
Definition: aeval.c:76
RMStream
Definition: rmdec.c:43
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
pts
static int64_t pts
Definition: transcode_aac.c:653
AVStream::duration
int64_t duration
Decoding: duration of the stream, in stream time base.
Definition: avformat.h:900
av_reduce
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
AVRational::num
int num
Numerator.
Definition: rational.h:59
get_num
static int get_num(AVIOContext *pb, int *len)
Definition: rmdec.c:665
AV_CODEC_ID_ATRAC3
@ AV_CODEC_ID_ATRAC3
Definition: codec_id.h:454
ff_rdt_demuxer
const AVInputFormat ff_rdt_demuxer
Definition: rmdec.c:1159
ff_rm_metadata
const char *const ff_rm_metadata[4]
Definition: rm.c:24
AV_CODEC_ID_SIPR
@ AV_CODEC_ID_SIPR
Definition: codec_id.h:464
avassert.h
avio_rb32
unsigned int avio_rb32(AVIOContext *s)
Definition: aviobuf.c:773
AV_LOG_TRACE
#define AV_LOG_TRACE
Extremely verbose debugging, useful for libav* development.
Definition: log.h:206
pkt
AVPacket * pkt
Definition: movenc.c:59
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
AVInputFormat
Definition: avformat.h:638
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
get_strl
static void get_strl(AVIOContext *pb, char *buf, int buf_size, int len)
Definition: rmdec.c:69
duration
int64_t duration
Definition: movenc.c:64
rm_read_packet
static int rm_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rmdec.c:1005
rm_read_audio_stream_info
static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, AVStream *st, RMStream *ast, int read_all)
Definition: rmdec.c:122
RMStream::slices
int slices
Definition: rmdec.c:48
intreadwrite.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
RMStream::audio_framesize
int audio_framesize
Definition: rmdec.c:54
av_new_packet
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:99
AVInputFormat::name
const char * name
A comma separated list of short names for the format.
Definition: avformat.h:643
AVProbeData::buf
unsigned char * buf
Buffer must have AVPROBE_PADDING_SIZE of extra allocated bytes filled with zero.
Definition: avformat.h:448
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecParameters::width
int width
Video only.
Definition: codec_par.h:126
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
rm_probe
static int rm_probe(const AVProbeData *p)
Definition: rmdec.c:1075
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
nb_streams
static int nb_streams
Definition: ffprobe.c:289
RMStream::pkt
AVPacket pkt
place to store merged video frame / reordered audio data
Definition: rmdec.c:44
RMStream::curpic_num
int curpic_num
picture number of current frame
Definition: rmdec.c:47
key
const char * key
Definition: hwcontext_opencl.c:168
AVMEDIA_TYPE_DATA
@ AVMEDIA_TYPE_DATA
Opaque data information usually continuous.
Definition: avutil.h:203
RMStream::pktpos
int64_t pktpos
first slice position in file
Definition: rmdec.c:49
if
if(ret)
Definition: filter_design.txt:179
ff_rm_parse_packet
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:885
FFStream::need_parsing
enum AVStreamParseType need_parsing
Definition: internal.h:402
RMStream::cur_slice
int cur_slice
Definition: rmdec.c:48
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AVFormatContext
Format I/O context.
Definition: avformat.h:1109
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1004
read_header
static int read_header(FFV1Context *f)
Definition: ffv1dec.c:527
ivr_read_header
static int ivr_read_header(AVFormatContext *s)
Definition: rmdec.c:1176
NULL
#define NULL
Definition: coverity.c:32
read_probe
static int read_probe(const AVProbeData *pd)
Definition: jvdec.c:55
ff_rm_codec_tags
const AVCodecTag ff_rm_codec_tags[]
Definition: rm.c:31
RMStream::sub_packet_size
int sub_packet_size
Definition: rmdec.c:53
ivr_read_packet
static int ivr_read_packet(AVFormatContext *s, AVPacket *pkt)
Definition: rmdec.c:1318
avio_rb64
uint64_t avio_rb64(AVIOContext *s)
Definition: aviobuf.c:920
AVProbeData
This structure contains the data a format has to probe a file.
Definition: avformat.h:446
RMDemuxContext
Definition: rmdec.c:59
rm_read_multi
static int rm_read_multi(AVFormatContext *s, AVIOContext *pb, AVStream *st, char *mime)
Definition: rmdec.c:501
RMDemuxContext::remaining_len
int remaining_len
Definition: rmdec.c:63
DEINT_ID_GENR
#define DEINT_ID_GENR
interleaving for Cooker/ATRAC
Definition: rmdec.c:36
RMStream::sub_packet_h
int sub_packet_h
Definition: rmdec.c:53
rm_read_metadata
static void rm_read_metadata(AVFormatContext *s, AVIOContext *pb, int wide)
Definition: rmdec.c:91
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1335
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:474
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: codec_par.h:170
DEINT_ID_INT4
#define DEINT_ID_INT4
interleaving for 28.8
Definition: rmdec.c:38
ivr_probe
static int ivr_probe(const AVProbeData *p)
Definition: rmdec.c:1167
AVCodecParameters::extradata_size
int extradata_size
Size of the extradata content in bytes.
Definition: codec_par.h:78
AV_CODEC_ID_AAC
@ AV_CODEC_ID_AAC
Definition: codec_id.h:425
RMDemuxContext::current_stream
int current_stream
Definition: rmdec.c:62
avio_rl32
unsigned int avio_rl32(AVIOContext *s)
Definition: aviobuf.c:742
ff_rm_alloc_rmstream
RMStream * ff_rm_alloc_rmstream(void)
Definition: rmdec.c:105
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:53
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
AVPacket::size
int size
Definition: packet.h:374
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
ff_codec_get_id
enum AVCodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag)
Definition: utils.c:357
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:262
FFStream
Definition: internal.h:191
start_time
static int64_t start_time
Definition: ffplay.c:330
avio_get_str
int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen)
Read a string from pb into buf.
Definition: aviobuf.c:878
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
rm_read_header
static int rm_read_header(AVFormatContext *s)
Definition: rmdec.c:542
AVFMT_NOFILE
#define AVFMT_NOFILE
Demuxer will use avio_open, no opened file should be provided by the caller.
Definition: avformat.h:463
avio_r8
int avio_r8(AVIOContext *s)
Definition: aviobuf.c:616
RMStream::sub_packet_lengths
int sub_packet_lengths[16]
Audio frame size from container.
Definition: rmdec.c:55
ffio_ensure_seekback
int ffio_ensure_seekback(AVIOContext *s, int64_t buf_size)
Ensures that the requested seekback buffer size will be available.
Definition: aviobuf.c:1016
offset
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
Definition: writing_filters.txt:86
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:379
version
version
Definition: libkvazaar.c:307
RMStream::sub_packet_cnt
int sub_packet_cnt
Definition: rmdec.c:52
ffio_limit
int ffio_limit(AVIOContext *s, int size)
Definition: aviobuf.c:1051
AV_CODEC_ID_RA_288
@ AV_CODEC_ID_RA_288
Definition: codec_id.h:411
rm_read_close
static int rm_read_close(AVFormatContext *s)
Definition: rmdec.c:1065
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: codec_id.h:48
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:366
avio_internal.h
internal.h
AVCodecParameters::height
int height
Definition: codec_par.h:127
AV_TIME_BASE
#define AV_TIME_BASE
Internal time base represented as integer.
Definition: avutil.h:254
AVCodecParameters::block_align
int block_align
Audio only.
Definition: codec_par.h:177
DEINT_ID_VBRF
#define DEINT_ID_VBRF
VBR case for AAC.
Definition: rmdec.c:40
rm_sync
static int rm_sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos)
Definition: rmdec.c:684
value
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default value
Definition: writing_filters.txt:86
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:263
len
int len
Definition: vorbis_enc_data.h:426
av_rescale
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:128
av_get_packet
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:196
tag
uint32_t tag
Definition: movenc.c:1595
AVStream::id
int id
Format-specific stream ID.
Definition: avformat.h:864
ret
ret
Definition: filter_design.txt:187
read_packet
static int read_packet(void *opaque, uint8_t *buf, int buf_size)
Definition: avio_reading.c:42
AVStream
Stream structure.
Definition: avformat.h:857
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
DEINT_ID_INT0
#define DEINT_ID_INT0
no interleaving needed
Definition: rmdec.c:37
RMDemuxContext::old_format
int old_format
Definition: rmdec.c:61
avio_rb16
unsigned int avio_rb16(AVIOContext *s)
Definition: aviobuf.c:758
sps
static int FUNC() sps(CodedBitstreamContext *ctx, RWContext *rw, H264RawSPS *current)
Definition: cbs_h264_syntax_template.c:260
AVSTREAM_PARSE_HEADERS
@ AVSTREAM_PARSE_HEADERS
Only parse headers, do not repack.
Definition: avformat.h:781
pos
unsigned int pos
Definition: spdifenc.c:412
avformat.h
ff_ivr_demuxer
const AVInputFormat ff_ivr_demuxer
Definition: rmdec.c:1399
dict.h
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
rm_ac3_swap_bytes
static void rm_ac3_swap_bytes(AVStream *st, AVPacket *pkt)
Definition: rmdec.c:860
ff_rm_free_rmstream
void ff_rm_free_rmstream(RMStream *rms)
Definition: rmdec.c:114
rm_read_dts
static int64_t rm_read_dts(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit)
Definition: rmdec.c:1088
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:858
RMStream::coded_framesize
int coded_framesize
Descrambling parameters from container.
Definition: rmdec.c:53
get_str8
static void get_str8(AVIOContext *pb, char *buf, int buf_size)
Definition: rmdec.c:77
channel_layout.h
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
ff_sipr_subpk_size
const unsigned char ff_sipr_subpk_size[4]
Definition: rmsipr.c:25
AVRational::den
int den
Denominator.
Definition: rational.h:60
avio_read
int avio_read(AVIOContext *s, unsigned char *buf, int size)
Read size bytes from AVIOContext into buf.
Definition: aviobuf.c:625
temp
else temp
Definition: vf_mcdeint.c:248
AVStream::r_frame_rate
AVRational r_frame_rate
Real base framerate of the stream.
Definition: avformat.h:993
AVSTREAM_PARSE_FULL_RAW
@ AVSTREAM_PARSE_FULL_RAW
full parsing and repack with timestamp and position generation by parser for raw this assumes that ea...
Definition: avformat.h:784
avpriv_set_pts_info
void avpriv_set_pts_info(AVStream *st, 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:1146
AVPacket::stream_index
int stream_index
Definition: packet.h:375
avio_skip
int64_t avio_skip(AVIOContext *s, int64_t offset)
Skip given number of bytes forward.
Definition: aviobuf.c:333
rm_read_seek
static int rm_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags)
Definition: rmdec.c:1134
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
RMStream::audiotimestamp
int64_t audiotimestamp
Audio descrambling matrix parameters.
Definition: rmdec.c:51
ff_rm_read_mdpr_codecdata
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:319
avpriv_request_sample
#define avpriv_request_sample(...)
Definition: tableprint_vlc.h:37
rm_assemble_video_frame
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:757
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: codec_par.h:60
AVPacket
This structure stores compressed data.
Definition: packet.h:350
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_set
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:70
AVPacket::pos
int64_t pos
byte position in stream, -1 if unknown
Definition: packet.h:393
AVCodecParameters::channel_layout
uint64_t channel_layout
Audio only.
Definition: codec_par.h:162
int32_t
int32_t
Definition: audioconvert.c:56
AVSTREAM_PARSE_FULL
@ AVSTREAM_PARSE_FULL
full parsing and repack
Definition: avformat.h:780
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: codec_par.h:89
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AV_CODEC_ID_COOK
@ AV_CODEC_ID_COOK
Definition: codec_id.h:443
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
rm.h
h
h
Definition: vp9dsp_template.c:2038
read_timestamp
static int64_t read_timestamp(AVFormatContext *s, int stream_index, int64_t *ppos, int64_t pos_limit, int64_t(*read_timestamp)(struct AVFormatContext *, int, int64_t *, int64_t))
Definition: seek.c:273
AVStream::start_time
int64_t start_time
Decoding: pts of the first frame of the stream in presentation order, in stream time base.
Definition: avformat.h:890
avstring.h
AVSTREAM_PARSE_TIMESTAMPS
@ AVSTREAM_PARSE_TIMESTAMPS
full parsing and interpolation of timestamps for frames not starting on a packet boundary
Definition: avformat.h:782
rm_read_header_old
static int rm_read_header_old(AVFormatContext *s)
Definition: rmdec.c:486
RMDemuxContext::audio_pkt_cnt
int audio_pkt_cnt
Output packet counter.
Definition: rmdec.c:65
RMDemuxContext::nb_packets
int nb_packets
Definition: rmdec.c:60
av_fourcc2str
#define av_fourcc2str(fourcc)
Definition: avutil.h:348
RMDemuxContext::audio_stream_num
int audio_stream_num
Stream number for audio packets.
Definition: rmdec.c:64
avio_feof
int avio_feof(AVIOContext *s)
Similar to feof() but also returns nonzero on read errors.
Definition: aviobuf.c:360