summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorBaptiste Coudurier <baptiste.coudurier@gmail.com>2006-04-14 10:51:32 +0000
committerBaptiste Coudurier <baptiste.coudurier@gmail.com>2006-04-14 10:51:32 +0000
commit5616f85deb729d181e2a923b2c74371fae6e8398 (patch)
treede40bfb6ba4a551e1d97ac61d6704b7a540627c7 /libavformat
parentb548f2b91b701e1235608ac882ea6df915167c7e (diff)
clean and simplify mov_write_packet
Originally committed as revision 5289 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/movenc.c66
1 files changed, 29 insertions, 37 deletions
diff --git a/libavformat/movenc.c b/libavformat/movenc.c
index a89ba9b622..af007ba8cc 100644
--- a/libavformat/movenc.c
+++ b/libavformat/movenc.c
@@ -1641,55 +1641,47 @@ static int mov_write_packet(AVFormatContext *s, AVPacket *pkt)
if (url_is_streamed(&s->pb)) return 0; /* Can't handle that */
if (!size) return 0; /* Discard 0 sized packets */
- if (enc->codec_type == CODEC_TYPE_VIDEO ) {
- samplesInChunk = 1;
- }
- else if (enc->codec_type == CODEC_TYPE_AUDIO ) {
- if( enc->codec_id == CODEC_ID_AMR_NB) {
- /* We must find out how many AMR blocks there are in one packet */
- static uint16_t packed_size[16] =
- {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
- int len = 0;
-
- while (len < size && samplesInChunk < 100) {
- len += packed_size[(pkt->data[len] >> 3) & 0x0F];
- samplesInChunk++;
+ if (enc->codec_type == CODEC_TYPE_AUDIO) {
+ switch (enc->codec_id) {
+ case CODEC_ID_AMR_NB:
+ { /* We must find out how many AMR blocks there are in one packet */
+ static uint16_t packed_size[16] =
+ {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0};
+ int len = 0;
+
+ while (len < size && samplesInChunk < 100) {
+ len += packed_size[(pkt->data[len] >> 3) & 0x0F];
+ samplesInChunk++;
+ }
}
- }
- else if(enc->codec_id == CODEC_ID_PCM_ALAW) {
+ break;
+ case CODEC_ID_PCM_ALAW:
samplesInChunk = size/enc->channels;
- }
- else if(enc->codec_id == CODEC_ID_PCM_S16BE || enc->codec_id == CODEC_ID_PCM_S16LE) {
+ break;
+ case CODEC_ID_PCM_S16BE:
+ case CODEC_ID_PCM_S16LE:
samplesInChunk = size/(2*enc->channels);
- }
- else {
+ break;
+ default:
samplesInChunk = 1;
}
+ } else {
+ samplesInChunk = 1;
}
- if ((enc->codec_id == CODEC_ID_MPEG4 || enc->codec_id == CODEC_ID_AAC)
- && trk->vosLen == 0) {
-// assert(enc->extradata_size);
-
+ /* copy extradata if it exists */
+ if (trk->vosLen == 0 && enc->extradata_size > 0) {
trk->vosLen = enc->extradata_size;
trk->vosData = av_malloc(trk->vosLen);
memcpy(trk->vosData, enc->extradata, trk->vosLen);
}
- if (enc->codec_id == CODEC_ID_H264) {
- if (trk->vosLen == 0) {
- /* copy extradata */
- trk->vosLen = enc->extradata_size;
- trk->vosData = av_malloc(trk->vosLen);
- memcpy(trk->vosData, enc->extradata, trk->vosLen);
- }
- if (*(uint8_t *)trk->vosData != 1) {
- /* from x264 or from bytestream h264 */
- /* nal reformating needed */
- avc_parse_nal_units(&pkt->data, &pkt->size);
- assert(pkt->size);
- size = pkt->size;
- }
+ if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) {
+ /* from x264 or from bytestream h264 */
+ /* nal reformating needed */
+ avc_parse_nal_units(&pkt->data, &pkt->size);
+ assert(pkt->size);
+ size = pkt->size;
}
cl = trk->entry / MOV_INDEX_CLUSTER_SIZE;