Mercurial > libavformat.hg
comparison movenc.c @ 2771:d52c718e83f9 libavformat
Use dynamically allocated ByteIOContext in AVFormatContext
patch by: Bj«Órn Axelsson, bjorn d axelsson a intinor d se
thread: [PATCH] Remove static ByteIOContexts, 06 nov 2007
author | andoma |
---|---|
date | Wed, 21 Nov 2007 07:41:00 +0000 |
parents | 09eb62fa2a0e |
children | ef333b18b760 |
comparison
equal
deleted
inserted
replaced
2770:a7e42cf4b364 | 2771:d52c718e83f9 |
---|---|
440 } | 440 } |
441 | 441 |
442 return end + 3; | 442 return end + 3; |
443 } | 443 } |
444 | 444 |
445 static void avc_parse_nal_units(uint8_t **buf, int *size) | 445 static int avc_parse_nal_units(uint8_t **buf, int *size) |
446 { | 446 { |
447 ByteIOContext pb; | 447 ByteIOContext *pb; |
448 uint8_t *p = *buf; | 448 uint8_t *p = *buf; |
449 uint8_t *end = p + *size; | 449 uint8_t *end = p + *size; |
450 uint8_t *nal_start, *nal_end; | 450 uint8_t *nal_start, *nal_end; |
451 | 451 int ret = url_open_dyn_buf(&pb); |
452 url_open_dyn_buf(&pb); | 452 if(ret < 0) |
453 return ret; | |
454 | |
453 nal_start = avc_find_startcode(p, end); | 455 nal_start = avc_find_startcode(p, end); |
454 while (nal_start < end) { | 456 while (nal_start < end) { |
455 while(!*(nal_start++)); | 457 while(!*(nal_start++)); |
456 nal_end = avc_find_startcode(nal_start, end); | 458 nal_end = avc_find_startcode(nal_start, end); |
457 put_be32(&pb, nal_end - nal_start); | 459 put_be32(pb, nal_end - nal_start); |
458 put_buffer(&pb, nal_start, nal_end - nal_start); | 460 put_buffer(pb, nal_start, nal_end - nal_start); |
459 nal_start = nal_end; | 461 nal_start = nal_end; |
460 } | 462 } |
461 av_freep(buf); | 463 av_freep(buf); |
462 *size = url_close_dyn_buf(&pb, buf); | 464 *size = url_close_dyn_buf(pb, buf); |
465 return 0; | |
463 } | 466 } |
464 | 467 |
465 static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track) | 468 static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track) |
466 { | 469 { |
467 offset_t pos = url_ftell(pb); | 470 offset_t pos = url_ftell(pb); |
1506 put_be32(pb, 0x010001); /* ? */ | 1509 put_be32(pb, 0x010001); /* ? */ |
1507 } | 1510 } |
1508 | 1511 |
1509 static int mov_write_header(AVFormatContext *s) | 1512 static int mov_write_header(AVFormatContext *s) |
1510 { | 1513 { |
1511 ByteIOContext *pb = &s->pb; | 1514 ByteIOContext *pb = s->pb; |
1512 MOVContext *mov = s->priv_data; | 1515 MOVContext *mov = s->priv_data; |
1513 int i; | 1516 int i; |
1514 | 1517 |
1515 if (url_is_streamed(&s->pb)) { | 1518 if (url_is_streamed(s->pb)) { |
1516 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); | 1519 av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); |
1517 return -1; | 1520 return -1; |
1518 } | 1521 } |
1519 | 1522 |
1520 /* Default mode == MP4 */ | 1523 /* Default mode == MP4 */ |
1577 } | 1580 } |
1578 | 1581 |
1579 static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) | 1582 static int mov_write_packet(AVFormatContext *s, AVPacket *pkt) |
1580 { | 1583 { |
1581 MOVContext *mov = s->priv_data; | 1584 MOVContext *mov = s->priv_data; |
1582 ByteIOContext *pb = &s->pb; | 1585 ByteIOContext *pb = s->pb; |
1583 MOVTrack *trk = &mov->tracks[pkt->stream_index]; | 1586 MOVTrack *trk = &mov->tracks[pkt->stream_index]; |
1584 AVCodecContext *enc = trk->enc; | 1587 AVCodecContext *enc = trk->enc; |
1585 unsigned int samplesInChunk = 0; | 1588 unsigned int samplesInChunk = 0; |
1586 int size= pkt->size; | 1589 int size= pkt->size; |
1587 | 1590 |
1588 if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */ | 1591 if (url_is_streamed(s->pb)) return 0; /* Can't handle that */ |
1589 if (!size) return 0; /* Discard 0 sized packets */ | 1592 if (!size) return 0; /* Discard 0 sized packets */ |
1590 | 1593 |
1591 if (enc->codec_id == CODEC_ID_AMR_NB) { | 1594 if (enc->codec_id == CODEC_ID_AMR_NB) { |
1592 /* We must find out how many AMR blocks there are in one packet */ | 1595 /* We must find out how many AMR blocks there are in one packet */ |
1593 static uint16_t packed_size[16] = | 1596 static uint16_t packed_size[16] = |
1661 } | 1664 } |
1662 | 1665 |
1663 static int mov_write_trailer(AVFormatContext *s) | 1666 static int mov_write_trailer(AVFormatContext *s) |
1664 { | 1667 { |
1665 MOVContext *mov = s->priv_data; | 1668 MOVContext *mov = s->priv_data; |
1666 ByteIOContext *pb = &s->pb; | 1669 ByteIOContext *pb = s->pb; |
1667 int res = 0; | 1670 int res = 0; |
1668 int i; | 1671 int i; |
1669 | 1672 |
1670 offset_t moov_pos = url_ftell(pb); | 1673 offset_t moov_pos = url_ftell(pb); |
1671 | 1674 |