Browse code

Merge remote-tracking branch 'qatar/master'

* qatar/master:
shorten: Use separate pointers for the allocated memory for decoded samples.
atrac3: Fix crash in tonal component decoding.
ws_snd1: Fix wrong samples counts.
movenc: Don't set a default sample duration when creating ismv
rtp: Factorize the check for distinguishing RTCP packets from RTP
golomb: avoid infinite loop on all-zero input (or end of buffer).
bethsoftvid: synchronize video timestamps with audio sample rate
bethsoftvid: add audio stream only after getting the first audio packet
bethsoftvid: Set video packet duration instead of accumulating pts.
bethsoftvid: set packet key frame flag for audio and I-frame video packets.
bethsoftvid: fix read_packet() return codes.
bethsoftvid: pass palette in side data instead of in a separate packet.
sdp: Ignore RTCP packets when autodetecting RTP streams
proresenc: initialise 'sign' variable
mpegaudio: replace memcpy by SIMD code
vc1: prevent using last_frame as a reference for I/P first frame.

Conflicts:
libavcodec/atrac3.c
libavcodec/golomb.h
libavcodec/shorten.c
libavcodec/ws-snd1.c
tests/ref/fate/bethsoft-vid

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2012/02/17 08:35:06
Showing 17 changed files
... ...
@@ -502,7 +502,7 @@ static int alloc_buffer(AVCodecContext *s, InputStream *ist, FrameBuffer **pbuf)
502 502
     /* XXX this shouldn't be needed, but some tests break without this line
503 503
      * those decoders are buggy and need to be fixed.
504 504
      * the following tests fail:
505
-     * bethsoft-vid, cdgraphics, ansi, aasc, fraps-v1, qtrle-1bit
505
+     * cdgraphics, ansi, aasc, fraps-v1, qtrle-1bit
506 506
      */
507 507
     memset(buf->base[0], 128, ret);
508 508
 
... ...
@@ -402,7 +402,7 @@ static int decodeTonalComponents (GetBitContext *gb, tonal_component *pComponent
402 402
 
403 403
             for (k=0; k<coded_components; k++) {
404 404
                 sfIndx = get_bits(gb,6);
405
-                if(component_count>=64)
405
+                if (component_count >= 64)
406 406
                     return AVERROR_INVALIDDATA;
407 407
                 pComponent[component_count].pos = j * 64 + (get_bits(gb,6));
408 408
                 max_coded_values = SAMPLES_PER_FRAME - pComponent[component_count].pos;
... ...
@@ -73,14 +73,23 @@ static int bethsoftvid_decode_frame(AVCodecContext *avctx,
73 73
     uint8_t * dst;
74 74
     uint8_t * frame_end;
75 75
     int remaining = avctx->width;          // number of bytes remaining on a line
76
-    const int wrap_to_next_line = vid->frame.linesize[0] - avctx->width;
77
-    int code;
76
+    int wrap_to_next_line;
77
+    int code, ret;
78 78
     int yoffset;
79 79
 
80 80
     if (avctx->reget_buffer(avctx, &vid->frame)) {
81 81
         av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n");
82 82
         return -1;
83 83
     }
84
+    wrap_to_next_line = vid->frame.linesize[0] - avctx->width;
85
+
86
+    if (avpkt->side_data_elems > 0 &&
87
+        avpkt->side_data[0].type == AV_PKT_DATA_PALETTE) {
88
+        bytestream2_init(&vid->g, avpkt->side_data[0].data,
89
+                         avpkt->side_data[0].size);
90
+        if ((ret = set_palette(vid)) < 0)
91
+            return ret;
92
+    }
84 93
 
85 94
     bytestream2_init(&vid->g, avpkt->data, avpkt->size);
86 95
     dst = vid->frame.data[0];
... ...
@@ -88,7 +97,6 @@ static int bethsoftvid_decode_frame(AVCodecContext *avctx,
88 88
 
89 89
     switch(block_type = bytestream2_get_byte(&vid->g)){
90 90
         case PALETTE_BLOCK: {
91
-            int ret;
92 91
             *data_size = 0;
93 92
             if ((ret = set_palette(vid)) < 0) {
94 93
                 av_log(avctx, AV_LOG_ERROR, "error reading palette\n");
... ...
@@ -265,6 +265,7 @@ static void encode_dcs(PutBitContext *pb, DCTELEM *blocks,
265 265
 
266 266
     prev_dc = (blocks[0] - 0x4000) / scale;
267 267
     encode_vlc_codeword(pb, FIRST_DC_CB, MAKE_CODE(prev_dc));
268
+    sign     = 0;
268 269
     codebook = 3;
269 270
     blocks  += 64;
270 271
 
... ...
@@ -409,6 +410,7 @@ static int estimate_dcs(int *error, DCTELEM *blocks, int blocks_per_slice,
409 409
 
410 410
     prev_dc  = (blocks[0] - 0x4000) / scale;
411 411
     bits     = estimate_vlc(FIRST_DC_CB, MAKE_CODE(prev_dc));
412
+    sign     = 0;
412 413
     codebook = 3;
413 414
     blocks  += 64;
414 415
     *error  += FFABS(blocks[0] - 0x4000) % scale;
... ...
@@ -141,7 +141,8 @@ static int allocate_buffers(ShortenContext *s)
141 141
             return AVERROR(ENOMEM);
142 142
         s->offset[chan] = tmp_ptr;
143 143
 
144
-        tmp_ptr = av_realloc(s->decoded_base[chan], sizeof(int32_t)*(s->blocksize + s->nwrap));
144
+        tmp_ptr = av_realloc(s->decoded_base[chan], (s->blocksize + s->nwrap) *
145
+                             sizeof(s->decoded_base[0][0]));
145 146
         if (!tmp_ptr)
146 147
             return AVERROR(ENOMEM);
147 148
         s->decoded_base[chan] = tmp_ptr;
... ...
@@ -478,7 +478,10 @@ static void vc1_mc_1mv(VC1Context *v, int dir)
478 478
     int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y;
479 479
     int off, off_uv;
480 480
     int v_edge_pos = s->v_edge_pos >> v->field_mode;
481
-    if (!v->field_mode && !v->s.last_picture.f.data[0])
481
+
482
+    if ((!v->field_mode ||
483
+         (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&
484
+        !v->s.last_picture.f.data[0])
482 485
         return;
483 486
 
484 487
     mx = s->mv[dir][0][0];
... ...
@@ -690,7 +693,9 @@ static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir)
690 690
     int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0;
691 691
     int v_edge_pos = s->v_edge_pos >> v->field_mode;
692 692
 
693
-    if (!v->field_mode && !v->s.last_picture.f.data[0])
693
+    if ((!v->field_mode ||
694
+         (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) &&
695
+        !v->s.last_picture.f.data[0])
694 696
         return;
695 697
 
696 698
     mx = s->mv[dir][n][0];
... ...
@@ -946,6 +951,8 @@ static void vc1_mc_4mv_chroma(VC1Context *v, int dir)
946 946
         if (dominant)
947 947
             chroma_ref_type = !v->cur_field_type;
948 948
     }
949
+    if (v->field_mode && chroma_ref_type == 1 && v->cur_field_type == 1 && !v->s.last_picture.f.data[0])
950
+        return;
949 951
     s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx;
950 952
     s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty;
951 953
     uvmx = (tx + ((tx & 3) == 3)) >> 1;
... ...
@@ -112,8 +112,8 @@ static int ws_snd_decode_frame(AVCodecContext *avctx, void *data,
112 112
 
113 113
         /* make sure we don't write past the output buffer */
114 114
         switch (code) {
115
-        case 0:  smp = 4*(count+1);                    break;
116
-        case 1:  smp = 2*(count+1);                    break;
115
+        case 0:  smp = 4 * (count + 1);                break;
116
+        case 1:  smp = 2 * (count + 1);                break;
117 117
         case 2:  smp = (count & 0x20) ? 1 : count + 1; break;
118 118
         default: smp = count + 1;                      break;
119 119
         }
... ...
@@ -106,7 +106,26 @@ static void apply_window_mp3(float *in, float *win, int *unused, float *out,
106 106
     float sum;
107 107
 
108 108
     /* copy to avoid wrap */
109
-    memcpy(in + 512, in, 32 * sizeof(*in));
109
+    __asm__ volatile(
110
+            "movaps    0(%0), %%xmm0   \n\t" \
111
+            "movaps   16(%0), %%xmm1   \n\t" \
112
+            "movaps   32(%0), %%xmm2   \n\t" \
113
+            "movaps   48(%0), %%xmm3   \n\t" \
114
+            "movaps   %%xmm0,   0(%1) \n\t" \
115
+            "movaps   %%xmm1,  16(%1) \n\t" \
116
+            "movaps   %%xmm2,  32(%1) \n\t" \
117
+            "movaps   %%xmm3,  48(%1) \n\t" \
118
+            "movaps   64(%0), %%xmm0   \n\t" \
119
+            "movaps   80(%0), %%xmm1   \n\t" \
120
+            "movaps   96(%0), %%xmm2   \n\t" \
121
+            "movaps  112(%0), %%xmm3   \n\t" \
122
+            "movaps   %%xmm0,  64(%1) \n\t" \
123
+            "movaps   %%xmm1,  80(%1) \n\t" \
124
+            "movaps   %%xmm2,  96(%1) \n\t" \
125
+            "movaps   %%xmm3, 112(%1) \n\t"
126
+            ::"r"(in), "r"(in+512)
127
+            :"memory"
128
+            );
110 129
 
111 130
     apply_window(in + 16, win     , win + 512, suma, sumc, 16);
112 131
     apply_window(in + 32, win + 48, win + 640, sumb, sumd, 16);
... ...
@@ -32,17 +32,23 @@
32 32
 #include "internal.h"
33 33
 #include "libavcodec/bethsoftvideo.h"
34 34
 
35
+#define BVID_PALETTE_SIZE 3 * 256
36
+
37
+#define DEFAULT_SAMPLE_RATE 11111
38
+
35 39
 typedef struct BVID_DemuxContext
36 40
 {
37 41
     int nframes;
42
+    int sample_rate;        /**< audio sample rate */
43
+    int width;              /**< video width       */
44
+    int height;             /**< video height      */
38 45
     /** delay value between frames, added to individual frame delay.
39 46
      * custom units, which will be added to other custom units (~=16ms according
40 47
      * to free, unofficial documentation) */
41 48
     int bethsoft_global_delay;
42
-
43
-    /** video presentation time stamp.
44
-     * delay = 16 milliseconds * (global_delay + per_frame_delay) */
45
-    int video_pts;
49
+    int video_index;        /**< video stream index */
50
+    int audio_index;        /**< audio stream index */
51
+    uint8_t *palette;
46 52
 
47 53
     int is_finished;
48 54
 
... ...
@@ -61,7 +67,6 @@ static int vid_read_header(AVFormatContext *s)
61 61
 {
62 62
     BVID_DemuxContext *vid = s->priv_data;
63 63
     AVIOContext *pb = s->pb;
64
-    AVStream *stream;
65 64
 
66 65
     /* load main header. Contents:
67 66
     *    bytes: 'V' 'I' 'D'
... ...
@@ -69,43 +74,50 @@ static int vid_read_header(AVFormatContext *s)
69 69
     */
70 70
     avio_skip(pb, 5);
71 71
     vid->nframes = avio_rl16(pb);
72
-
73
-    stream = avformat_new_stream(s, NULL);
74
-    if (!stream)
75
-        return AVERROR(ENOMEM);
76
-    avpriv_set_pts_info(stream, 32, 1, 60);     // 16 ms increments, i.e. 60 fps
77
-    stream->codec->codec_type = AVMEDIA_TYPE_VIDEO;
78
-    stream->codec->codec_id = CODEC_ID_BETHSOFTVID;
79
-    stream->codec->width = avio_rl16(pb);
80
-    stream->codec->height = avio_rl16(pb);
81
-    stream->codec->pix_fmt = PIX_FMT_PAL8;
72
+    vid->width   = avio_rl16(pb);
73
+    vid->height  = avio_rl16(pb);
82 74
     vid->bethsoft_global_delay = avio_rl16(pb);
83 75
     avio_rl16(pb);
84 76
 
85
-    // done with video codec, set up audio codec
86
-    stream = avformat_new_stream(s, NULL);
87
-    if (!stream)
88
-        return AVERROR(ENOMEM);
89
-    stream->codec->codec_type = AVMEDIA_TYPE_AUDIO;
90
-    stream->codec->codec_id = CODEC_ID_PCM_U8;
91
-    stream->codec->channels = 1;
92
-    stream->codec->sample_rate = 11025;
93
-    stream->codec->bits_per_coded_sample = 8;
94
-    stream->codec->bit_rate = stream->codec->channels * stream->codec->sample_rate * stream->codec->bits_per_coded_sample;
77
+    // wait until the first packet to create each stream
78
+    vid->video_index = -1;
79
+    vid->audio_index = -1;
80
+    vid->sample_rate = DEFAULT_SAMPLE_RATE;
81
+    s->ctx_flags |= AVFMTCTX_NOHEADER;
95 82
 
96 83
     return 0;
97 84
 }
98 85
 
99 86
 #define BUFFER_PADDING_SIZE 1000
100 87
 static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt,
101
-                      uint8_t block_type, AVFormatContext *s, int npixels)
88
+                      uint8_t block_type, AVFormatContext *s)
102 89
 {
103 90
     uint8_t * vidbuf_start = NULL;
104 91
     int vidbuf_nbytes = 0;
105 92
     int code;
106 93
     int bytes_copied = 0;
107
-    int position;
94
+    int position, duration, npixels;
108 95
     unsigned int vidbuf_capacity;
96
+    int ret = 0;
97
+    AVStream *st;
98
+
99
+    if (vid->video_index < 0) {
100
+        st = avformat_new_stream(s, NULL);
101
+        if (!st)
102
+            return AVERROR(ENOMEM);
103
+        vid->video_index = st->index;
104
+        if (vid->audio_index < 0) {
105
+            av_log_ask_for_sample(s, "No audio packet before first video "
106
+                                  "packet. Using default video time base.\n");
107
+        }
108
+        avpriv_set_pts_info(st, 64, 185, vid->sample_rate);
109
+        st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
110
+        st->codec->codec_id   = CODEC_ID_BETHSOFTVID;
111
+        st->codec->width      = vid->width;
112
+        st->codec->height     = vid->height;
113
+    }
114
+    st      = s->streams[vid->video_index];
115
+    npixels = st->codec->width * st->codec->height;
109 116
 
110 117
     vidbuf_start = av_malloc(vidbuf_capacity = BUFFER_PADDING_SIZE);
111 118
     if(!vidbuf_start)
... ...
@@ -116,13 +128,15 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt,
116 116
 
117 117
     vidbuf_start[vidbuf_nbytes++] = block_type;
118 118
 
119
-    // get the video delay (next int16), and set the presentation time
120
-    vid->video_pts += vid->bethsoft_global_delay + avio_rl16(pb);
119
+    // get the current packet duration
120
+    duration = vid->bethsoft_global_delay + avio_rl16(pb);
121 121
 
122 122
     // set the y offset if it exists (decoder header data should be in data section)
123 123
     if(block_type == VIDEO_YOFF_P_FRAME){
124
-        if(avio_read(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2)
124
+        if (avio_read(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2) {
125
+            ret = AVERROR(EIO);
125 126
             goto fail;
127
+        }
126 128
         vidbuf_nbytes += 2;
127 129
     }
128 130
 
... ...
@@ -138,8 +152,10 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt,
138 138
             if(block_type == VIDEO_I_FRAME)
139 139
                 vidbuf_start[vidbuf_nbytes++] = avio_r8(pb);
140 140
         } else if(code){ // plain sequence
141
-            if(avio_read(pb, &vidbuf_start[vidbuf_nbytes], code) != code)
141
+            if (avio_read(pb, &vidbuf_start[vidbuf_nbytes], code) != code) {
142
+                ret = AVERROR(EIO);
142 143
                 goto fail;
144
+            }
143 145
             vidbuf_nbytes += code;
144 146
         }
145 147
         bytes_copied += code & 0x7F;
... ...
@@ -149,25 +165,37 @@ static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt,
149 149
                 avio_seek(pb, -1, SEEK_CUR);
150 150
             break;
151 151
         }
152
-        if(bytes_copied > npixels)
152
+        if (bytes_copied > npixels) {
153
+            ret = AVERROR_INVALIDDATA;
153 154
             goto fail;
155
+        }
154 156
     } while(code);
155 157
 
156 158
     // copy data into packet
157
-    if(av_new_packet(pkt, vidbuf_nbytes) < 0)
159
+    if ((ret = av_new_packet(pkt, vidbuf_nbytes)) < 0)
158 160
         goto fail;
159 161
     memcpy(pkt->data, vidbuf_start, vidbuf_nbytes);
160 162
     av_free(vidbuf_start);
161 163
 
162 164
     pkt->pos = position;
163
-    pkt->stream_index = 0;  // use the video decoder, which was initialized as the first stream
164
-    pkt->pts = vid->video_pts;
165
+    pkt->stream_index = vid->video_index;
166
+    pkt->duration = duration;
167
+    if (block_type == VIDEO_I_FRAME)
168
+        pkt->flags |= AV_PKT_FLAG_KEY;
169
+
170
+    /* if there is a new palette available, add it to packet side data */
171
+    if (vid->palette) {
172
+        uint8_t *pdata = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE,
173
+                                                 BVID_PALETTE_SIZE);
174
+        memcpy(pdata, vid->palette, BVID_PALETTE_SIZE);
175
+        av_freep(&vid->palette);
176
+    }
165 177
 
166 178
     vid->nframes--;  // used to check if all the frames were read
167
-    return vidbuf_nbytes;
179
+    return 0;
168 180
 fail:
169 181
     av_free(vidbuf_start);
170
-    return -1;
182
+    return ret;
171 183
 }
172 184
 
173 185
 static int vid_read_packet(AVFormatContext *s,
... ...
@@ -185,31 +213,54 @@ static int vid_read_packet(AVFormatContext *s,
185 185
     block_type = avio_r8(pb);
186 186
     switch(block_type){
187 187
         case PALETTE_BLOCK:
188
-            avio_seek(pb, -1, SEEK_CUR);     // include block type
189
-            ret_value = av_get_packet(pb, pkt, 3 * 256 + 1);
190
-            if(ret_value != 3 * 256 + 1){
191
-                av_free_packet(pkt);
188
+            if (vid->palette) {
189
+                av_log(s, AV_LOG_WARNING, "discarding unused palette\n");
190
+                av_freep(&vid->palette);
191
+            }
192
+            vid->palette = av_malloc(BVID_PALETTE_SIZE);
193
+            if (!vid->palette)
194
+                return AVERROR(ENOMEM);
195
+            if (avio_read(pb, vid->palette, BVID_PALETTE_SIZE) != BVID_PALETTE_SIZE) {
196
+                av_freep(&vid->palette);
192 197
                 return AVERROR(EIO);
193 198
             }
194
-            pkt->stream_index = 0;
195
-            return ret_value;
199
+            return vid_read_packet(s, pkt);
196 200
 
197 201
         case FIRST_AUDIO_BLOCK:
198 202
             avio_rl16(pb);
199 203
             // soundblaster DAC used for sample rate, as on specification page (link above)
200
-            s->streams[1]->codec->sample_rate = 1000000 / (256 - avio_r8(pb));
201
-            s->streams[1]->codec->bit_rate = s->streams[1]->codec->channels * s->streams[1]->codec->sample_rate * s->streams[1]->codec->bits_per_coded_sample;
204
+            vid->sample_rate = 1000000 / (256 - avio_r8(pb));
202 205
         case AUDIO_BLOCK:
206
+            if (vid->audio_index < 0) {
207
+                AVStream *st = avformat_new_stream(s, NULL);
208
+                if (!st)
209
+                    return AVERROR(ENOMEM);
210
+                vid->audio_index                 = st->index;
211
+                st->codec->codec_type            = AVMEDIA_TYPE_AUDIO;
212
+                st->codec->codec_id              = CODEC_ID_PCM_U8;
213
+                st->codec->channels              = 1;
214
+                st->codec->bits_per_coded_sample = 8;
215
+                st->codec->sample_rate           = vid->sample_rate;
216
+                st->codec->bit_rate              = 8 * st->codec->sample_rate;
217
+                st->start_time                   = 0;
218
+                avpriv_set_pts_info(st, 64, 1, vid->sample_rate);
219
+            }
203 220
             audio_length = avio_rl16(pb);
204
-            ret_value = av_get_packet(pb, pkt, audio_length);
205
-            pkt->stream_index = 1;
206
-            return ret_value != audio_length ? AVERROR(EIO) : ret_value;
221
+            if ((ret_value = av_get_packet(pb, pkt, audio_length)) != audio_length) {
222
+                if (ret_value < 0)
223
+                    return ret_value;
224
+                av_log(s, AV_LOG_ERROR, "incomplete audio block\n");
225
+                return AVERROR(EIO);
226
+            }
227
+            pkt->stream_index = vid->audio_index;
228
+            pkt->duration     = audio_length;
229
+            pkt->flags |= AV_PKT_FLAG_KEY;
230
+            return 0;
207 231
 
208 232
         case VIDEO_P_FRAME:
209 233
         case VIDEO_YOFF_P_FRAME:
210 234
         case VIDEO_I_FRAME:
211
-            return read_frame(vid, pb, pkt, block_type, s,
212
-                              s->streams[0]->codec->width * s->streams[0]->codec->height);
235
+            return read_frame(vid, pb, pkt, block_type, s);
213 236
 
214 237
         case EOF_BLOCK:
215 238
             if(vid->nframes != 0)
... ...
@@ -218,10 +269,18 @@ static int vid_read_packet(AVFormatContext *s,
218 218
             return AVERROR(EIO);
219 219
         default:
220 220
             av_log(s, AV_LOG_ERROR, "unknown block (character = %c, decimal = %d, hex = %x)!!!\n",
221
-                   block_type, block_type, block_type); return -1;
221
+                   block_type, block_type, block_type);
222
+            return AVERROR_INVALIDDATA;
222 223
     }
223 224
 }
224 225
 
226
+static int vid_read_close(AVFormatContext *s)
227
+{
228
+    BVID_DemuxContext *vid = s->priv_data;
229
+    av_freep(&vid->palette);
230
+    return 0;
231
+}
232
+
225 233
 AVInputFormat ff_bethsoftvid_demuxer = {
226 234
     .name           = "bethsoftvid",
227 235
     .long_name      = NULL_IF_CONFIG_SMALL("Bethesda Softworks VID format"),
... ...
@@ -229,4 +288,5 @@ AVInputFormat ff_bethsoftvid_demuxer = {
229 229
     .read_probe     = vid_probe,
230 230
     .read_header    = vid_read_header,
231 231
     .read_packet    = vid_read_packet,
232
+    .read_close     = vid_read_close,
232 233
 };
... ...
@@ -2230,10 +2230,11 @@ static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track,
2230 2230
         flags |= 0x20; /* default-sample-flags-present */
2231 2231
     }
2232 2232
 
2233
-    /* Don't set a default sample size when creating data for silverlight,
2234
-     * the player refuses to play files with that set. */
2233
+    /* Don't set a default sample size, the silverlight player refuses
2234
+     * to play files with that set. Don't set a default sample duration,
2235
+     * WMP freaks out if it is set. */
2235 2236
     if (track->mode == MODE_ISM)
2236
-        flags &= ~0x10;
2237
+        flags &= ~0x18;
2237 2238
 
2238 2239
     avio_wb32(pb, 0); /* size placeholder */
2239 2240
     ffio_wfourcc(pb, "tfhd");
... ...
@@ -333,7 +333,7 @@ static int write_hint_packets(AVIOContext *out, const uint8_t *data,
333 333
         size -= 4;
334 334
         if (packet_len > size || packet_len <= 12)
335 335
             break;
336
-        if (data[1] >= RTCP_SR && data[1] <= RTCP_APP) {
336
+        if (RTP_PT_IS_RTCP(data[1])) {
337 337
             /* RTCP packet, just skip */
338 338
             data += packet_len;
339 339
             size -= packet_len;
... ...
@@ -91,4 +91,6 @@ enum RTCPType {
91 91
     RTCP_APP   // 204
92 92
 };
93 93
 
94
+#define RTP_PT_IS_RTCP(x) ((x) >= RTCP_SR && (x) <= RTCP_APP)
95
+
94 96
 #endif /* AVFORMAT_RTP_H */
... ...
@@ -695,7 +695,7 @@ static int rtp_parse_one_packet(RTPDemuxContext *s, AVPacket *pkt,
695 695
 
696 696
     if ((buf[0] & 0xc0) != (RTP_VERSION << 6))
697 697
         return -1;
698
-    if (buf[1] >= RTCP_SR && buf[1] <= RTCP_APP) {
698
+    if (RTP_PT_IS_RTCP(buf[1])) {
699 699
         return rtcp_parse_packet(s, buf, len);
700 700
     }
701 701
 
... ...
@@ -267,7 +267,7 @@ static int rtp_write(URLContext *h, const uint8_t *buf, int size)
267 267
     int ret;
268 268
     URLContext *hd;
269 269
 
270
-    if (buf[1] >= RTCP_SR && buf[1] <= RTCP_APP) {
270
+    if (RTP_PT_IS_RTCP(buf[1])) {
271 271
         /* RTCP payload type */
272 272
         hd = s->rtcp_hd;
273 273
     } else {
... ...
@@ -1922,6 +1922,9 @@ static int rtp_read_header(AVFormatContext *s)
1922 1922
             continue;
1923 1923
         }
1924 1924
 
1925
+        if (RTP_PT_IS_RTCP(recvbuf[1]))
1926
+            continue;
1927
+
1925 1928
         payload_type = recvbuf[1] & 0x7f;
1926 1929
         break;
1927 1930
     }
... ...
@@ -159,7 +159,7 @@ static int tcp_write_packet(AVFormatContext *s, RTSPStream *rtsp_st)
159 159
         size -= 4;
160 160
         if (packet_len > size || packet_len < 2)
161 161
             break;
162
-        if (ptr[1] >= RTCP_SR && ptr[1] <= RTCP_APP)
162
+        if (RTP_PT_IS_RTCP(ptr[1]))
163 163
             id = rtsp_st->interleaved_max; /* RTCP */
164 164
         else
165 165
             id = rtsp_st->interleaved_min; /* RTP */
... ...
@@ -1,143 +1,144 @@
1
-#tb 0: 1/60
1
+#tb 0: 1/14
2 2
 #tb 1: 1/11111
3
+0,          0,          0,        1,   192000, 0x00000000
3 4
 1,          0,          0,      740,     1480, 0x00000000
4
-0,          1,          1,        1,   192000, 0x00000000
5 5
 1,        740,        740,      740,     1480, 0x20a92bd4
6
-0,          5,          5,        1,   192000, 0x5a5acf57
6
+0,          1,          1,        1,   192000, 0x5a5acf57
7 7
 1,       1480,       1480,      925,     1850, 0xa9e48a74
8
-0,         10,         10,        1,   192000, 0xbd055cf1
8
+0,          2,          2,        1,   192000, 0xbd055cf1
9
+0,          3,          3,        1,   192000, 0x28b1eefc
9 10
 1,       2405,       2405,      740,     1480, 0x23ecd018
10
-0,         14,         14,        1,   192000, 0x28b1eefc
11 11
 1,       3145,       3145,      740,     1480, 0x206bb915
12
-0,         18,         18,        1,   192000, 0x0636bacd
12
+0,          4,          4,        1,   192000, 0x0636bacd
13 13
 1,       3885,       3885,      925,     1850, 0xb0e10e75
14
-0,         23,         23,        1,   192000, 0xbfd33cbd
14
+0,          5,          5,        1,   192000, 0xbfd33cbd
15
+0,          6,          6,        1,   192000, 0x0bd150ef
15 16
 1,       4810,       4810,      740,     1480, 0x8d9baedd
16
-0,         27,         27,        1,   192000, 0x0bd150ef
17 17
 1,       5550,       5550,      740,     1480, 0xb802aae1
18
-0,         31,         31,        1,   192000, 0x780d891e
18
+0,          7,          7,        1,   192000, 0x780d891e
19 19
 1,       6290,       6290,      740,     1480, 0xecd7b5cc
20
-0,         35,         35,        1,   192000, 0xacf5e205
20
+0,          8,          8,        1,   192000, 0xacf5e205
21 21
 1,       7030,       7030,      925,     1850, 0x16861355
22
-0,         40,         40,        1,   192000, 0x37c900dc
22
+0,          9,          9,        1,   192000, 0x37c900dc
23
+0,         10,         10,        1,   192000, 0x4ee6add7
23 24
 1,       7955,       7955,      740,     1480, 0xa51690bd
24
-0,         44,         44,        1,   192000, 0x4ee6add7
25 25
 1,       8695,       8695,      740,     1480, 0xdd0b90d1
26
-0,         48,         48,        1,   192000, 0x1844783a
26
+0,         11,         11,        1,   192000, 0x1844783a
27 27
 1,       9435,       9435,      925,     1850, 0x3ce6e333
28
-0,         53,         53,        1,   192000, 0x7bf84848
28
+0,         12,         12,        1,   192000, 0x7bf84848
29
+0,         13,         13,        1,   192000, 0x1ec296bc
29 30
 1,      10360,      10360,      740,     1480, 0xf8ce8ea3
30
-0,         57,         57,        1,   192000, 0x1ec296bc
31 31
 1,      11100,      11100,      740,     1480, 0xda4597af
32
-0,         61,         61,        1,   192000, 0xbaeb5292
32
+0,         14,         14,        1,   192000, 0xbaeb5292
33 33
 1,      11840,      11840,      740,     1480, 0x918f7cb3
34
-0,         65,         65,        1,   192000, 0xcb18038d
34
+0,         15,         15,        1,   192000, 0xcb18038d
35 35
 1,      12580,      12580,      925,     1850, 0xca6edb15
36
-0,         70,         70,        1,   192000, 0xb3cc8b65
36
+0,         16,         16,        1,   192000, 0xb3cc8b65
37
+0,         17,         17,        1,   192000, 0x6f164685
37 38
 1,      13505,      13505,      740,     1480, 0xba279597
38
-0,         74,         74,        1,   192000, 0x6f164685
39 39
 1,      14245,      14245,      740,     1480, 0xc5a38a9e
40
-0,         78,         78,        1,   192000, 0x304917c9
40
+0,         18,         18,        1,   192000, 0x304917c9
41 41
 1,      14985,      14985,      925,     1850, 0x8147eef5
42
-0,         83,         83,        1,   192000, 0x8269daa1
42
+0,         19,         19,        1,   192000, 0x8269daa1
43
+0,         20,         20,        1,   192000, 0x04d3500d
43 44
 1,      15910,      15910,      740,     1480, 0xce2c7cb5
44
-0,         87,         87,        1,   192000, 0x04d3500d
45 45
 1,      16650,      16650,      740,     1480, 0x4282819f
46
-0,         91,         91,        1,   192000, 0x9788f7a5
46
+0,         21,         21,        1,   192000, 0x9788f7a5
47 47
 1,      17390,      17390,      740,     1480, 0xbdbb8da6
48
-0,         95,         95,        1,   192000, 0x05351c98
48
+0,         22,         22,        1,   192000, 0x05351c98
49 49
 1,      18130,      18130,      925,     1850, 0xdbbeea10
50
-0,        100,        100,        1,   192000, 0xcc8bba97
50
+0,         23,         23,        1,   192000, 0xcc8bba97
51
+0,         24,         24,        1,   192000, 0x76caf27b
51 52
 1,      19055,      19055,      740,     1480, 0xbe6a77c2
52
-0,        104,        104,        1,   192000, 0x76caf27b
53 53
 1,      19795,      19795,      740,     1480, 0xa85c75b2
54
-0,        108,        108,        1,   192000, 0x28648040
54
+0,         25,         25,        1,   192000, 0x28648040
55 55
 1,      20535,      20535,      925,     1850, 0xa45bde21
56
-0,        113,        113,        1,   192000, 0x99ea251f
56
+0,         26,         26,        1,   192000, 0x99ea251f
57
+0,         27,         27,        1,   192000, 0x20e7bf4d
57 58
 1,      21460,      21460,      740,     1480, 0x84aa7895
58
-0,        117,        117,        1,   192000, 0x20e7bf4d
59 59
 1,      22200,      22200,      740,     1480, 0x147f7d9f
60
-0,        121,        121,        1,   192000, 0x046ed625
60
+0,         28,         28,        1,   192000, 0x046ed625
61 61
 1,      22940,      22940,      740,     1480, 0xc8e77b85
62
-0,        125,        125,        1,   192000, 0x1613fb12
62
+0,         29,         29,        1,   192000, 0x1613fb12
63 63
 1,      23680,      23680,      925,     1850, 0x10d4d81b
64
-0,        130,        130,        1,   192000, 0xd8b52d16
64
+0,         30,         30,        1,   192000, 0xd8b52d16
65
+0,         31,         31,        1,   192000, 0x31443aa9
65 66
 1,      24605,      24605,      740,     1480, 0xb4ae8bb1
66
-0,        134,        134,        1,   192000, 0x31443aa9
67 67
 1,      25345,      25345,      740,     1480, 0x3ef782a5
68
-0,        138,        138,        1,   192000, 0xd426de3d
68
+0,         32,         32,        1,   192000, 0xd426de3d
69 69
 1,      26085,      26085,      925,     1850, 0xdeebda14
70
-0,        143,        143,        1,   192000, 0xb2bce77b
70
+0,         33,         33,        1,   192000, 0xb2bce77b
71
+0,         34,         34,        1,   192000, 0x25a52805
71 72
 1,      27010,      27010,      740,     1480, 0x4c7e7bbb
72
-0,        147,        147,        1,   192000, 0x25a52805
73 73
 1,      27750,      27750,      740,     1480, 0x0e0e9198
74
-0,        151,        151,        1,   192000, 0x04f03a87
74
+0,         35,         35,        1,   192000, 0x04f03a87
75 75
 1,      28490,      28490,      740,     1480, 0x5c1f819f
76
-0,        155,        155,        1,   192000, 0x41d56889
76
+0,         36,         36,        1,   192000, 0x41d56889
77 77
 1,      29230,      29230,      925,     1850, 0x0e4cf6ff
78
-0,        160,        160,        1,   192000, 0x3d4d6de9
78
+0,         37,         37,        1,   192000, 0x3d4d6de9
79 79
 1,      30155,      30155,      740,     1480, 0x374388a7
80
-0,        164,        164,        1,   192000, 0xa7a2abfe
80
+0,         38,         38,        1,   192000, 0xa7a2abfe
81 81
 1,      30895,      30895,      740,     1480, 0xed729389
82
-0,        168,        168,        1,   192000, 0x663e9fca
82
+0,         39,         39,        1,   192000, 0x663e9fca
83 83
 1,      31635,      31635,      925,     1850, 0xe0f1e43f
84
-0,        173,        173,        1,   192000, 0x29a67f86
84
+0,         40,         40,        1,   192000, 0x29a67f86
85
+0,         41,         41,        1,   192000, 0x51531bb0
85 86
 1,      32560,      32560,      740,     1480, 0x3b27839a
86
-0,        177,        177,        1,   192000, 0x51531bb0
87 87
 1,      33300,      33300,      740,     1480, 0xe6287e94
88
-0,        181,        181,        1,   192000, 0xd993277e
88
+0,         42,         42,        1,   192000, 0xd993277e
89 89
 1,      34040,      34040,      740,     1480, 0x7e0d84b5
90
-0,        185,        185,        1,   192000, 0x4873e583
90
+0,         43,         43,        1,   192000, 0x4873e583
91 91
 1,      34780,      34780,      925,     1850, 0xf08bebf7
92
-0,        190,        190,        1,   192000, 0x06df053b
92
+0,         44,         44,        1,   192000, 0x06df053b
93 93
 1,      35705,      35705,      740,     1480, 0x94cf73a0
94
-0,        194,        194,        1,   192000, 0x044f7698
94
+0,         45,         45,        1,   192000, 0x044f7698
95 95
 1,      36445,      36445,      740,     1480, 0xfef384ae
96
-0,        198,        198,        1,   192000, 0xc2302a45
96
+0,         46,         46,        1,   192000, 0xc2302a45
97 97
 1,      37185,      37185,      925,     1850, 0x3b93e0f7
98
-0,        203,        203,        1,   192000, 0xbdfec8ee
98
+0,         47,         47,        1,   192000, 0xbdfec8ee
99
+0,         48,         48,        1,   192000, 0x3b739286
99 100
 1,      38110,      38110,      740,     1480, 0x28d27bae
100
-0,        207,        207,        1,   192000, 0x3b739286
101 101
 1,      38850,      38850,      740,     1480, 0x94d57da5
102
-0,        211,        211,        1,   192000, 0x3ca82cd6
102
+0,         49,         49,        1,   192000, 0x3ca82cd6
103 103
 1,      39590,      39590,      740,     1480, 0xc9327db5
104
-0,        215,        215,        1,   192000, 0x25af10f2
104
+0,         50,         50,        1,   192000, 0x25af10f2
105 105
 1,      40330,      40330,      925,     1850, 0xe781f604
106
-0,        220,        220,        1,   192000, 0x09ce32bf
106
+0,         51,         51,        1,   192000, 0x09ce32bf
107 107
 1,      41255,      41255,      740,     1480, 0x752f8c5b
108
-0,        224,        224,        1,   192000, 0xdab399c2
108
+0,         52,         52,        1,   192000, 0xdab399c2
109 109
 1,      41995,      41995,      740,     1480, 0x30068032
110
-0,        228,        228,        1,   192000, 0x77400d93
110
+0,         53,         53,        1,   192000, 0x77400d93
111 111
 1,      42735,      42735,      925,     1850, 0x7895023e
112
-0,        233,        233,        1,   192000, 0x5e8e6fe7
112
+0,         54,         54,        1,   192000, 0x5e8e6fe7
113
+0,         55,         55,        1,   192000, 0x277506c9
113 114
 1,      43660,      43660,      740,     1480, 0xa1e0a6e1
114
-0,        237,        237,        1,   192000, 0x277506c9
115 115
 1,      44400,      44400,      740,     1480, 0x6af4b500
116
-0,        241,        241,        1,   192000, 0xe91b59ac
116
+0,         56,         56,        1,   192000, 0xe91b59ac
117 117
 1,      45140,      45140,      740,     1480, 0xc26ea4c7
118
-0,        245,        245,        1,   192000, 0xc2aa6e19
118
+0,         57,         57,        1,   192000, 0xc2aa6e19
119 119
 1,      45880,      45880,      925,     1850, 0x16a72419
120
-0,        250,        250,        1,   192000, 0x12c63645
120
+0,         58,         58,        1,   192000, 0x12c63645
121 121
 1,      46805,      46805,      740,     1480, 0x1794aacc
122
-0,        254,        254,        1,   192000, 0xa39f27d6
122
+0,         59,         59,        1,   192000, 0xa39f27d6
123 123
 1,      47545,      47545,      740,     1480, 0x2ecad8d0
124
-0,        258,        258,        1,   192000, 0x20c32512
124
+0,         60,         60,        1,   192000, 0x20c32512
125 125
 1,      48285,      48285,      925,     1850, 0x2e645e07
126
-0,        263,        263,        1,   192000, 0x385a26a0
126
+0,         61,         61,        1,   192000, 0x385a26a0
127
+0,         62,         62,        1,   192000, 0x2566a70c
127 128
 1,      49210,      49210,      740,     1480, 0x1c54dfe7
128
-0,        267,        267,        1,   192000, 0x2566a70c
129 129
 1,      49950,      49950,      740,     1480, 0xbd35feec
130
-0,        271,        271,        1,   192000, 0x7105cfb9
130
+0,         63,         63,        1,   192000, 0x7105cfb9
131 131
 1,      50690,      50690,      740,     1480, 0x419403d6
132
-0,        275,        275,        1,   192000, 0x725671a2
132
+0,         64,         64,        1,   192000, 0x725671a2
133 133
 1,      51430,      51430,      925,     1850, 0x78699d2a
134
-0,        280,        280,        1,   192000, 0x3ff2782a
134
+0,         65,         65,        1,   192000, 0x3ff2782a
135 135
 1,      52355,      52355,      740,     1480, 0x74ec68e0
136
-0,        284,        284,        1,   192000, 0xdc0571c3
136
+0,         66,         66,        1,   192000, 0xdc0571c3
137 137
 1,      53095,      53095,      740,     1480, 0x76af64d9
138
-0,        288,        288,        1,   192000, 0x4a6a5405
138
+0,         67,         67,        1,   192000, 0x4a6a5405
139 139
 1,      53835,      53835,      925,     1850, 0x5a303d1a
140
-0,        293,        293,        1,   192000, 0x3ec3cce1
140
+0,         68,         68,        1,   192000, 0x3ec3cce1
141 141
 1,      54760,      54760,      537,     1074, 0x142ce7ba
142
-0,        297,        297,        1,   192000, 0x159313a8
142
+0,         69,         69,        1,   192000, 0x159313a8
143 143
 1,      55297,      55297,      925,     1850, 0x7ff682f7
144
+0,         70,         70,        1,   192000, 0x8e685d68