Mercurial > libavformat.hg
comparison mpeg.c @ 242:3c299d432ca4 libavformat
removed invalid sequence end code
author | bellard |
---|---|
date | Wed, 10 Sep 2003 22:44:30 +0000 |
parents | 3d92f793fd67 |
children | 3dd3646e0164 |
comparison
equal
deleted
inserted
replaced
241:3d92f793fd67 | 242:3c299d432ca4 |
---|---|
248 } | 248 } |
249 return -ENOMEM; | 249 return -ENOMEM; |
250 } | 250 } |
251 | 251 |
252 /* flush the packet on stream stream_index */ | 252 /* flush the packet on stream stream_index */ |
253 static void flush_packet(AVFormatContext *ctx, int stream_index, int last_pkt) | 253 static void flush_packet(AVFormatContext *ctx, int stream_index) |
254 { | 254 { |
255 MpegMuxContext *s = ctx->priv_data; | 255 MpegMuxContext *s = ctx->priv_data; |
256 StreamInfo *stream = ctx->streams[stream_index]->priv_data; | 256 StreamInfo *stream = ctx->streams[stream_index]->priv_data; |
257 uint8_t *buf_ptr; | 257 uint8_t *buf_ptr; |
258 int size, payload_size, startcode, id, len, stuffing_size, i, header_len; | 258 int size, payload_size, startcode, id, len, stuffing_size, i, header_len; |
259 int64_t timestamp; | 259 int64_t timestamp; |
260 uint8_t buffer[128]; | 260 uint8_t buffer[128]; |
261 int last = last_pkt ? 4 : 0; | |
262 | 261 |
263 id = stream->id; | 262 id = stream->id; |
264 timestamp = stream->start_pts; | 263 timestamp = stream->start_pts; |
265 | 264 |
266 #if 0 | 265 #if 0 |
285 if (s->is_mpeg2) { | 284 if (s->is_mpeg2) { |
286 header_len = 8; | 285 header_len = 8; |
287 } else { | 286 } else { |
288 header_len = 5; | 287 header_len = 5; |
289 } | 288 } |
290 payload_size = s->packet_size - (size + 6 + header_len + last); | 289 payload_size = s->packet_size - (size + 6 + header_len); |
291 if (id < 0xc0) { | 290 if (id < 0xc0) { |
292 startcode = PRIVATE_STREAM_1; | 291 startcode = PRIVATE_STREAM_1; |
293 payload_size -= 4; | 292 payload_size -= 4; |
294 } else { | 293 } else { |
295 startcode = 0x100 + id; | 294 startcode = 0x100 + id; |
325 put_byte(&ctx->pb, 0); | 324 put_byte(&ctx->pb, 0); |
326 put_byte(&ctx->pb, 2); | 325 put_byte(&ctx->pb, 2); |
327 } | 326 } |
328 } | 327 } |
329 | 328 |
330 if (last_pkt) { | |
331 put_be32(&ctx->pb, ISO_11172_END_CODE); | |
332 } | |
333 /* output data */ | 329 /* output data */ |
334 put_buffer(&ctx->pb, stream->buffer, payload_size - stuffing_size); | 330 put_buffer(&ctx->pb, stream->buffer, payload_size - stuffing_size); |
335 put_flush_packet(&ctx->pb); | 331 put_flush_packet(&ctx->pb); |
336 | 332 |
337 /* preserve remaining data */ | 333 /* preserve remaining data */ |
368 size -= len; | 364 size -= len; |
369 while (stream->buffer_ptr >= s->packet_data_max_size) { | 365 while (stream->buffer_ptr >= s->packet_data_max_size) { |
370 /* output the packet */ | 366 /* output the packet */ |
371 if (stream->start_pts == -1) | 367 if (stream->start_pts == -1) |
372 stream->start_pts = pts; | 368 stream->start_pts = pts; |
373 flush_packet(ctx, stream_index, 0); | 369 flush_packet(ctx, stream_index); |
374 } | 370 } |
375 } | 371 } |
376 return 0; | 372 return 0; |
377 } | 373 } |
378 | 374 |
383 | 379 |
384 /* flush each packet */ | 380 /* flush each packet */ |
385 for(i=0;i<ctx->nb_streams;i++) { | 381 for(i=0;i<ctx->nb_streams;i++) { |
386 stream = ctx->streams[i]->priv_data; | 382 stream = ctx->streams[i]->priv_data; |
387 if (stream->buffer_ptr > 0) { | 383 if (stream->buffer_ptr > 0) { |
388 if (i == (ctx->nb_streams - 1)) | 384 flush_packet(ctx, i); |
389 flush_packet(ctx, i, 1); | 385 } |
390 else | 386 } |
391 flush_packet(ctx, i, 0); | 387 |
392 } | 388 /* End header according to MPEG1 systems standard. We do not write |
393 } | 389 it as it is usually not needed by decoders and because it |
394 | 390 complicates MPEG stream concatenation. */ |
395 /* write the end header */ | |
396 //put_be32(&ctx->pb, ISO_11172_END_CODE); | 391 //put_be32(&ctx->pb, ISO_11172_END_CODE); |
397 //put_flush_packet(&ctx->pb); | 392 //put_flush_packet(&ctx->pb); |
398 | 393 |
399 for(i=0;i<ctx->nb_streams;i++) | 394 for(i=0;i<ctx->nb_streams;i++) |
400 av_freep(&ctx->streams[i]->priv_data); | 395 av_freep(&ctx->streams[i]->priv_data); |