annotate nutenc.c @ 6479:3e7384f85f1d libavformat

tcp: Check both wfds and efds when waiting for the result from connect On windows, a connection failure doesn't trigger wfds as it does on unix. This fixes issue 2237, based on code by yeyingxian.
author mstorsjo
date Tue, 21 Sep 2010 20:17:34 +0000
parents b3aea89a4f63
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
1 /*
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
2 * nut muxer
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
3 * Copyright (c) 2004-2007 Michael Niedermayer
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
4 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
5 * This file is part of FFmpeg.
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
6 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
11 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
16 *
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
20 */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
21
4201
7d2f3f1b68d8 Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents: 4076
diff changeset
22 #include "libavutil/intreadwrite.h"
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3135
diff changeset
23 #include "libavutil/tree.h"
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3135
diff changeset
24 #include "libavcodec/mpegaudiodata.h"
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
25 #include "nut.h"
6033
c7b98381ec2d Move AVCodecTag from riff.h into internal.h.
cehoyos
parents: 5913
diff changeset
26 #include "internal.h"
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
27
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
28 static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64]){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
29 int sample_rate= c->sample_rate;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
30
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
31 if(size>4096)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
32 return 0;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
33
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
34 AV_WB24(out, 1);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
35
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
36 if(c->codec_id == CODEC_ID_MPEG4){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
37 if(key_frame){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
38 return 3;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
39 }else{
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
40 out[3]= 0xB6;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
41 return 4;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
42 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
43 }else if(c->codec_id == CODEC_ID_MPEG1VIDEO || c->codec_id == CODEC_ID_MPEG2VIDEO){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
44 return 3;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
45 }else if(c->codec_id == CODEC_ID_H264){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
46 return 3;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
47 }else if(c->codec_id == CODEC_ID_MP3 || c->codec_id == CODEC_ID_MP2){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
48 int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
49 int layer= c->codec_id == CODEC_ID_MP3 ? 3 : 2;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
50 unsigned int header= 0xFFF00000;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
51
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
52 lsf = sample_rate < (24000+32000)/2;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
53 mpeg25 = sample_rate < (12000+16000)/2;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
54 sample_rate <<= lsf + mpeg25;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
55 if (sample_rate < (32000 + 44100)/2) sample_rate_index=2;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
56 else if(sample_rate < (44100 + 48000)/2) sample_rate_index=0;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
57 else sample_rate_index=1;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
58
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
59 sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
60
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
61 for(bitrate_index=2; bitrate_index<30; bitrate_index++){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
62 frame_size = ff_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1];
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
63 frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
64
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
65 if(frame_size == size)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
66 break;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
67 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
68
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
69 header |= (!lsf)<<19;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
70 header |= (4-layer)<<17;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
71 header |= 1<<16; //no crc
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
72 AV_WB32(out, header);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
73 if(size <= 0)
3135
cf8df6a00eb5 misc spelling fixes
diego
parents: 3120
diff changeset
74 return 2; //we guess there is no crc, if there is one the user clearly does not care about overhead
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
75 if(bitrate_index == 30)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
76 return -1; //something is wrong ...
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
77
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
78 header |= (bitrate_index>>1)<<12;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
79 header |= sample_rate_index<<10;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
80 header |= (bitrate_index&1)<<9;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
81
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
82 return 2; //FIXME actually put the needed ones in build_elision_headers()
3135
cf8df6a00eb5 misc spelling fixes
diego
parents: 3120
diff changeset
83 return 3; //we guess that the private bit is not set
cf8df6a00eb5 misc spelling fixes
diego
parents: 3120
diff changeset
84 //FIXME the above assumptions should be checked, if these turn out false too often something should be done
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
85 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
86 return 0;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
87 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
88
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
89 static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
90 NUTContext *nut = s->priv_data;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
91 uint8_t out[64];
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
92 int i;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
93 int len= find_expected_header(c, size, frame_type, out);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
94
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
95 //av_log(NULL, AV_LOG_ERROR, "expected_h len=%d size=%d codec_id=%d\n", len, size, c->codec_id);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
96
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
97 for(i=1; i<nut->header_count; i++){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
98 if( len == nut->header_len[i]
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
99 && !memcmp(out, nut->header[i], len)){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
100 // av_log(NULL, AV_LOG_ERROR, "found %d\n", i);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
101 return i;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
102 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
103 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
104 // av_log(NULL, AV_LOG_ERROR, "nothing found\n");
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
105 return 0;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
106 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
107
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
108 static void build_elision_headers(AVFormatContext *s){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
109 NUTContext *nut = s->priv_data;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
110 int i;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
111 //FIXME this is lame
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
112 //FIXME write a 2pass mode to find the maximal headers
4520
c9ef08e6e4a9 cosmetics: 'const static' --> 'static const' to avoid warnings of the type
diego
parents: 4206
diff changeset
113 static const uint8_t headers[][5]={
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
114 {3, 0x00, 0x00, 0x01},
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
115 {4, 0x00, 0x00, 0x01, 0xB6},
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
116 {2, 0xFF, 0xFA}, //mp3+crc
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
117 {2, 0xFF, 0xFB}, //mp3
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
118 {2, 0xFF, 0xFC}, //mp2+crc
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
119 {2, 0xFF, 0xFD}, //mp2
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
120 };
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
121
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
122 nut->header_count= 7;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
123 for(i=1; i<nut->header_count; i++){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
124 nut->header_len[i]= headers[i-1][0];
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
125 nut->header [i]= &headers[i-1][1];
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
126 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
127 }
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
128
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
129 static void build_frame_code(AVFormatContext *s){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
130 NUTContext *nut = s->priv_data;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
131 int key_frame, index, pred, stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
132 int start=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
133 int end= 254;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
134 int keyframe_0_esc= s->nb_streams > 2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
135 int pred_table[10];
2339
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
136 FrameCode *ft;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
137
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
138 ft= &nut->frame_code[start];
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
139 ft->flags= FLAG_CODED;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
140 ft->size_mul=1;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
141 ft->pts_delta=1;
2c8579bcd287 add a universal fallback frame code for the case that no other applies
michael
parents: 2332
diff changeset
142 start++;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
143
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
144 if(keyframe_0_esc){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
145 /* keyframe = 0 escape */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
146 FrameCode *ft= &nut->frame_code[start];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
147 ft->flags= FLAG_STREAM_ID | FLAG_SIZE_MSB | FLAG_CODED_PTS;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
148 ft->size_mul=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
149 start++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
150 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
151
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
152 for(stream_id= 0; stream_id<s->nb_streams; stream_id++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
153 int start2= start + (end-start)*stream_id / s->nb_streams;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
154 int end2 = start + (end-start)*(stream_id+1) / s->nb_streams;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
155 AVCodecContext *codec = s->streams[stream_id]->codec;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5902
diff changeset
156 int is_audio= codec->codec_type == AVMEDIA_TYPE_AUDIO;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
157 int intra_only= /*codec->intra_only || */is_audio;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
158 int pred_count;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
159
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
160 for(key_frame=0; key_frame<2; key_frame++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
161 if(intra_only && keyframe_0_esc && key_frame==0)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
162 continue;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
163
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
164 {
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
165 FrameCode *ft= &nut->frame_code[start2];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
166 ft->flags= FLAG_KEY*key_frame;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
167 ft->flags|= FLAG_SIZE_MSB | FLAG_CODED_PTS;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
168 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
169 ft->size_mul=1;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
170 if(is_audio)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
171 ft->header_idx= find_header_idx(s, codec, -1, key_frame);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
172 start2++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
173 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
174 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
175
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
176 key_frame= intra_only;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
177 #if 1
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
178 if(is_audio){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
179 int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
180 int pts;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
181 for(pts=0; pts<2; pts++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
182 for(pred=0; pred<2; pred++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
183 FrameCode *ft= &nut->frame_code[start2];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
184 ft->flags= FLAG_KEY*key_frame;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
185 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
186 ft->size_mul=frame_bytes + 2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
187 ft->size_lsb=frame_bytes + pred;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
188 ft->pts_delta=pts;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
189 ft->header_idx= find_header_idx(s, codec, frame_bytes + pred, key_frame);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
190 start2++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
191 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
192 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
193 }else{
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
194 FrameCode *ft= &nut->frame_code[start2];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
195 ft->flags= FLAG_KEY | FLAG_SIZE_MSB;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
196 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
197 ft->size_mul=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
198 ft->pts_delta=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
199 start2++;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
200 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
201 #endif
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
202
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
203 if(codec->has_b_frames){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
204 pred_count=5;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
205 pred_table[0]=-2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
206 pred_table[1]=-1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
207 pred_table[2]=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
208 pred_table[3]=3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
209 pred_table[4]=4;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
210 }else if(codec->codec_id == CODEC_ID_VORBIS){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
211 pred_count=3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
212 pred_table[0]=2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
213 pred_table[1]=9;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
214 pred_table[2]=16;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
215 }else{
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
216 pred_count=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
217 pred_table[0]=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
218 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
219
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
220 for(pred=0; pred<pred_count; pred++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
221 int start3= start2 + (end2-start2)*pred / pred_count;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
222 int end3 = start2 + (end2-start2)*(pred+1) / pred_count;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
223
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
224 for(index=start3; index<end3; index++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
225 FrameCode *ft= &nut->frame_code[index];
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
226 ft->flags= FLAG_KEY*key_frame;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
227 ft->flags|= FLAG_SIZE_MSB;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
228 ft->stream_id= stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
229 //FIXME use single byte size and pred from last
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
230 ft->size_mul= end3-start3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
231 ft->size_lsb= index - start3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
232 ft->pts_delta= pred_table[pred];
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
233 if(is_audio)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
234 ft->header_idx= find_header_idx(s, codec, -1, key_frame);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
235 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
236 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
237 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
238 memmove(&nut->frame_code['N'+1], &nut->frame_code['N'], sizeof(FrameCode)*(255-'N'));
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
239 nut->frame_code[ 0].flags=
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
240 nut->frame_code[255].flags=
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
241 nut->frame_code['N'].flags= FLAG_INVALID;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
242 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
243
4076
a5c615b9d8ec remove _t for POSIX compatibility.
michael
parents: 3766
diff changeset
244 static void put_tt(NUTContext *nut, StreamContext *nus, ByteIOContext *bc, uint64_t val){
2342
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
245 val *= nut->time_base_count;
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
246 val += nus->time_base - nut->time_base;
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
247 ff_put_v(bc, val);
2342
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
248 }
dfb3b2cff096 put_t()
michael
parents: 2341
diff changeset
249
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
250 /**
6199
fa244b4fe683 Fix grammar errors in documentation
mru
parents: 6075
diff changeset
251 * Store a string as vb.
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
252 */
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
253 static void put_str(ByteIOContext *bc, const char *string){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
254 int len= strlen(string);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
255
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
256 ff_put_v(bc, len);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
257 put_buffer(bc, string, len);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
258 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
259
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
260 static void put_s(ByteIOContext *bc, int64_t val){
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
261 ff_put_v(bc, 2*FFABS(val) - (val>0));
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
262 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
263
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
264 #ifdef TRACE
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
265 static inline void ff_put_v_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
266 av_log(NULL, AV_LOG_DEBUG, "ff_put_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
267
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
268 ff_put_v(bc, v);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
269 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
270
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
271 static inline void put_s_trace(ByteIOContext *bc, int64_t v, char *file, char *func, int line){
2344
a7fd892b1a57 get rid of printf
michael
parents: 2343
diff changeset
272 av_log(NULL, AV_LOG_DEBUG, "put_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
273
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
274 put_s(bc, v);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
275 }
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
276 #define ff_put_v(bc, v) ff_put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
277 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
278 #endif
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
279
2340
ab5509871fd2 2 FIXME comments
michael
parents: 2339
diff changeset
280 //FIXME remove calculate_checksum
2347
5c32dd0eafc6 fix header_checksum
michael
parents: 2346
diff changeset
281 static void put_packet(NUTContext *nut, ByteIOContext *bc, ByteIOContext *dyn_bc, int calculate_checksum, uint64_t startcode){
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
282 uint8_t *dyn_buf=NULL;
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
283 int dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf);
2332
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
284 int forw_ptr= dyn_size + 4*calculate_checksum;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
285
2332
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
286 if(forw_ptr > 4096)
2683
153d6efc05b8 rename av_crc04C11DB7_update to ff_crc04C11DB7_update and move it to aviobuf.c so it can be reused by other (de)muxers
bcoudurier
parents: 2393
diff changeset
287 init_checksum(bc, ff_crc04C11DB7_update, 0);
2347
5c32dd0eafc6 fix header_checksum
michael
parents: 2346
diff changeset
288 put_be64(bc, startcode);
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
289 ff_put_v(bc, forw_ptr);
2332
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
290 if(forw_ptr > 4096)
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
291 put_le32(bc, get_checksum(bc));
7dd23262372f forw_ptr CRC
michael
parents: 2331
diff changeset
292
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
293 if(calculate_checksum)
2683
153d6efc05b8 rename av_crc04C11DB7_update to ff_crc04C11DB7_update and move it to aviobuf.c so it can be reused by other (de)muxers
bcoudurier
parents: 2393
diff changeset
294 init_checksum(bc, ff_crc04C11DB7_update, 0);
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
295 put_buffer(bc, dyn_buf, dyn_size);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
296 if(calculate_checksum)
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
297 put_le32(bc, get_checksum(bc));
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
298
2331
4d1a56112d92 use a dynamic ByteIOContext instead of using the lavf buffer
michael
parents: 2330
diff changeset
299 av_free(dyn_buf);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
300 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
301
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
302 static void write_mainheader(NUTContext *nut, ByteIOContext *bc){
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
303 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields, tmp_head_idx;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
304 int64_t tmp_match;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
305
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
306 ff_put_v(bc, 3); /* version */
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
307 ff_put_v(bc, nut->avf->nb_streams);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
308 ff_put_v(bc, nut->max_distance);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
309 ff_put_v(bc, nut->time_base_count);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
310
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
311 for(i=0; i<nut->time_base_count; i++){
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
312 ff_put_v(bc, nut->time_base[i].num);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
313 ff_put_v(bc, nut->time_base[i].den);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
314 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
315
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
316 tmp_pts=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
317 tmp_mul=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
318 tmp_stream=0;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
319 tmp_match= 1-(1LL<<62);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
320 tmp_head_idx= 0;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
321 for(i=0; i<256;){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
322 tmp_fields=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
323 tmp_size=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
324 // tmp_res=0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
325 if(tmp_pts != nut->frame_code[i].pts_delta) tmp_fields=1;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
326 if(tmp_mul != nut->frame_code[i].size_mul ) tmp_fields=2;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
327 if(tmp_stream != nut->frame_code[i].stream_id) tmp_fields=3;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
328 if(tmp_size != nut->frame_code[i].size_lsb ) tmp_fields=4;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
329 // if(tmp_res != nut->frame_code[i].res ) tmp_fields=5;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
330 if(tmp_head_idx!=nut->frame_code[i].header_idx)tmp_fields=8;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
331
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
332 tmp_pts = nut->frame_code[i].pts_delta;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
333 tmp_flags = nut->frame_code[i].flags;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
334 tmp_stream= nut->frame_code[i].stream_id;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
335 tmp_mul = nut->frame_code[i].size_mul;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
336 tmp_size = nut->frame_code[i].size_lsb;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
337 // tmp_res = nut->frame_code[i].res;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
338 tmp_head_idx= nut->frame_code[i].header_idx;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
339
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
340 for(j=0; i<256; j++,i++){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
341 if(i == 'N'){
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
342 j--;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
343 continue;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
344 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
345 if(nut->frame_code[i].pts_delta != tmp_pts ) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
346 if(nut->frame_code[i].flags != tmp_flags ) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
347 if(nut->frame_code[i].stream_id != tmp_stream) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
348 if(nut->frame_code[i].size_mul != tmp_mul ) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
349 if(nut->frame_code[i].size_lsb != tmp_size+j) break;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
350 // if(nut->frame_code[i].res != tmp_res ) break;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
351 if(nut->frame_code[i].header_idx!= tmp_head_idx) break;
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
352 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
353 if(j != tmp_mul - tmp_size) tmp_fields=6;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
354
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
355 ff_put_v(bc, tmp_flags);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
356 ff_put_v(bc, tmp_fields);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
357 if(tmp_fields>0) put_s(bc, tmp_pts);
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
358 if(tmp_fields>1) ff_put_v(bc, tmp_mul);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
359 if(tmp_fields>2) ff_put_v(bc, tmp_stream);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
360 if(tmp_fields>3) ff_put_v(bc, tmp_size);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
361 if(tmp_fields>4) ff_put_v(bc, 0 /*tmp_res*/);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
362 if(tmp_fields>5) ff_put_v(bc, j);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
363 if(tmp_fields>6) ff_put_v(bc, tmp_match);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
364 if(tmp_fields>7) ff_put_v(bc, tmp_head_idx);
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
365 }
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
366 ff_put_v(bc, nut->header_count-1);
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
367 for(i=1; i<nut->header_count; i++){
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
368 ff_put_v(bc, nut->header_len[i]);
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
369 put_buffer(bc, nut->header[i], nut->header_len[i]);
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
370 }
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
371 }
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
372
6072
0475ccdb762d Make write_streamheader() and write_headers() accept an
stefano
parents: 6038
diff changeset
373 static int write_streamheader(AVFormatContext *avctx, ByteIOContext *bc, AVStream *st, int i){
0475ccdb762d Make write_streamheader() and write_headers() accept an
stefano
parents: 6038
diff changeset
374 NUTContext *nut = avctx->priv_data;
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3623
diff changeset
375 AVCodecContext *codec = st->codec;
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
376 ff_put_v(bc, i);
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
377 switch(codec->codec_type){
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
378 case AVMEDIA_TYPE_VIDEO: ff_put_v(bc, 0); break;
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
379 case AVMEDIA_TYPE_AUDIO: ff_put_v(bc, 1); break;
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
380 case AVMEDIA_TYPE_SUBTITLE: ff_put_v(bc, 2); break;
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
381 default : ff_put_v(bc, 3); break;
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
382 }
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
383 ff_put_v(bc, 4);
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
384 if (codec->codec_tag){
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
385 put_le32(bc, codec->codec_tag);
6075
be118b3b67a8 Make write_streamheader() log a message if there is no codec tag
stefano
parents: 6074
diff changeset
386 } else {
be118b3b67a8 Make write_streamheader() log a message if there is no codec tag
stefano
parents: 6074
diff changeset
387 av_log(avctx, AV_LOG_ERROR, "No codec tag defined for stream %d\n", i);
6074
258c2ccc68b5 Make write_streamheader() return a meaningful error code if no codec
stefano
parents: 6073
diff changeset
388 return AVERROR(EINVAL);
6075
be118b3b67a8 Make write_streamheader() log a message if there is no codec tag
stefano
parents: 6074
diff changeset
389 }
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
390
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
391 ff_put_v(bc, nut->stream[i].time_base - nut->time_base);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
392 ff_put_v(bc, nut->stream[i].msb_pts_shift);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
393 ff_put_v(bc, nut->stream[i].max_pts_distance);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
394 ff_put_v(bc, codec->has_b_frames);
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
395 put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
396
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
397 ff_put_v(bc, codec->extradata_size);
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
398 put_buffer(bc, codec->extradata, codec->extradata_size);
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
399
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
400 switch(codec->codec_type){
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5902
diff changeset
401 case AVMEDIA_TYPE_AUDIO:
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
402 ff_put_v(bc, codec->sample_rate);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
403 ff_put_v(bc, 1);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
404 ff_put_v(bc, codec->channels);
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
405 break;
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5902
diff changeset
406 case AVMEDIA_TYPE_VIDEO:
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
407 ff_put_v(bc, codec->width);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
408 ff_put_v(bc, codec->height);
2363
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
409
3759
27537074f2a9 convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents: 3623
diff changeset
410 if(st->sample_aspect_ratio.num<=0 || st->sample_aspect_ratio.den<=0){
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
411 ff_put_v(bc, 0);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
412 ff_put_v(bc, 0);
2363
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
413 }else{
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
414 ff_put_v(bc, st->sample_aspect_ratio.num);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
415 ff_put_v(bc, st->sample_aspect_ratio.den);
2363
3f3a4b5fc5bb ensure that the aspect ratio is spec compliant
michael
parents: 2361
diff changeset
416 }
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
417 ff_put_v(bc, 0); /* csp type -- unknown */
2330
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
418 break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
419 default:
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
420 break;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
421 }
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
422 return 0;
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
423 }
c25f63f009a8 move stream header writing into its own function
michael
parents: 2329
diff changeset
424
3004
327814e7bf03 Missing const found by -Wwrite-strings.
michael
parents: 2939
diff changeset
425 static int add_info(ByteIOContext *bc, const char *type, const char *value){
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
426 put_str(bc, type);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
427 put_s(bc, -1);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
428 put_str(bc, value);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
429 return 1;
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
430 }
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
431
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
432 static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
433 AVFormatContext *s= nut->avf;
5704
6b9c2a6d8fa4 Introduce metadata conversion table for NUT muxer and demuxer.
kostya
parents: 5058
diff changeset
434 AVMetadataTag *t = NULL;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
435 ByteIOContext *dyn_bc;
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
436 uint8_t *dyn_buf=NULL;
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
437 int count=0, dyn_size;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
438 int ret = url_open_dyn_buf(&dyn_bc);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
439 if(ret < 0)
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
440 return ret;
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
441
5704
6b9c2a6d8fa4 Introduce metadata conversion table for NUT muxer and demuxer.
kostya
parents: 5058
diff changeset
442 while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX)))
6b9c2a6d8fa4 Introduce metadata conversion table for NUT muxer and demuxer.
kostya
parents: 5058
diff changeset
443 count += add_info(dyn_bc, t->key, t->value);
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
444
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
445 ff_put_v(bc, 0); //stream_if_plus1
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
446 ff_put_v(bc, 0); //chapter_id
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
447 ff_put_v(bc, 0); //timestamp_start
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
448 ff_put_v(bc, 0); //length
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
449
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
450 ff_put_v(bc, count);
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
451
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
452 dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf);
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
453 put_buffer(bc, dyn_buf, dyn_size);
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
454 av_free(dyn_buf);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
455 return 0;
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
456 }
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
457
3120
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
458 static int write_streaminfo(NUTContext *nut, ByteIOContext *bc, int stream_id){
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
459 AVFormatContext *s= nut->avf;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
460 AVStream* st = s->streams[stream_id];
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
461 ByteIOContext *dyn_bc;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
462 uint8_t *dyn_buf=NULL;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
463 int count=0, dyn_size, i;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
464 int ret = url_open_dyn_buf(&dyn_bc);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
465 if(ret < 0)
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
466 return ret;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
467
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
468 for (i=0; ff_nut_dispositions[i].flag; ++i) {
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
469 if (st->disposition & ff_nut_dispositions[i].flag)
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
470 count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
471 }
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
472 dyn_size = url_close_dyn_buf(dyn_bc, &dyn_buf);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
473
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
474 if (count) {
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
475 ff_put_v(bc, stream_id + 1); //stream_id_plus1
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
476 ff_put_v(bc, 0); //chapter_id
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
477 ff_put_v(bc, 0); //timestamp_start
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
478 ff_put_v(bc, 0); //length
3120
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
479
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
480 ff_put_v(bc, count);
3120
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
481
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
482 put_buffer(bc, dyn_buf, dyn_size);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
483 }
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
484
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
485 av_free(dyn_buf);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
486 return count;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
487 }
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
488
6072
0475ccdb762d Make write_streamheader() and write_headers() accept an
stefano
parents: 6038
diff changeset
489 static int write_headers(AVFormatContext *avctx, ByteIOContext *bc){
0475ccdb762d Make write_streamheader() and write_headers() accept an
stefano
parents: 6038
diff changeset
490 NUTContext *nut = avctx->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
491 ByteIOContext *dyn_bc;
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
492 int i, ret;
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
493
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
494 ret = url_open_dyn_buf(&dyn_bc);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
495 if(ret < 0)
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
496 return ret;
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
497 write_mainheader(nut, dyn_bc);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
498 put_packet(nut, bc, dyn_bc, 1, MAIN_STARTCODE);
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
499
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
500 for (i=0; i < nut->avf->nb_streams; i++){
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
501 ret = url_open_dyn_buf(&dyn_bc);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
502 if(ret < 0)
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
503 return ret;
6073
b9ddee1ca18c Make write_header() and write_header() return an error code in case of
stefano
parents: 6072
diff changeset
504 if ((ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i)) < 0)
b9ddee1ca18c Make write_header() and write_header() return an error code in case of
stefano
parents: 6072
diff changeset
505 return ret;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
506 put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE);
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
507 }
2358
ed9b81f74317 info packet
michael
parents: 2355
diff changeset
508
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
509 ret = url_open_dyn_buf(&dyn_bc);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
510 if(ret < 0)
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
511 return ret;
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
512 write_globalinfo(nut, dyn_bc);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
513 put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
514
3120
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
515 for (i = 0; i < nut->avf->nb_streams; i++) {
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
516 ret = url_open_dyn_buf(&dyn_bc);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
517 if(ret < 0)
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
518 return ret;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
519 ret = write_streaminfo(nut, dyn_bc, i);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
520 if (ret < 0)
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
521 return ret;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
522 if (ret > 0)
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
523 put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
524 else {
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
525 uint8_t* buf;
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
526 url_close_dyn_buf(dyn_bc, &buf);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
527 av_free(buf);
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
528 }
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
529 }
ea5623a8efde Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents: 3112
diff changeset
530
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
531 nut->last_syncpoint_pos= INT_MIN;
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
532 nut->header_count++;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
533 return 0;
2345
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
534 }
b73b443c43d0 move header writing into its own function
michael
parents: 2344
diff changeset
535
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
536 static int write_header(AVFormatContext *s){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
537 NUTContext *nut = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
538 ByteIOContext *bc = s->pb;
6073
b9ddee1ca18c Make write_header() and write_header() return an error code in case of
stefano
parents: 6072
diff changeset
539 int i, j, ret;
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
540
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
541 nut->avf= s;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
542
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
543 nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
544 nut->time_base= av_mallocz(sizeof(AVRational )*s->nb_streams);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
545
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
546 for(i=0; i<s->nb_streams; i++){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
547 AVStream *st= s->streams[i];
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
548 int ssize;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
549 AVRational time_base;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
550 ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
551
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
552 av_set_pts_info(st, 64, time_base.num, time_base.den);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
553
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
554 for(j=0; j<nut->time_base_count; j++){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
555 if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
556 break;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
557 }
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
558 }
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
559 nut->time_base[j]= time_base;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
560 nut->stream[i].time_base= &nut->time_base[j];
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
561 if(j==nut->time_base_count)
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
562 nut->time_base_count++;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
563
6471
b3aea89a4f63 nutenc: fix unstable floating-point calculations
mru
parents: 6246
diff changeset
564 if(INT64_C(1000) * time_base.num >= time_base.den)
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
565 nut->stream[i].msb_pts_shift = 7;
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
566 else
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
567 nut->stream[i].msb_pts_shift = 14;
6471
b3aea89a4f63 nutenc: fix unstable floating-point calculations
mru
parents: 6246
diff changeset
568 nut->stream[i].max_pts_distance= FFMAX(time_base.den, time_base.num) / time_base.num;
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
569 }
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
570
3014
66fb9d4dea91 nut->max_distance was not set at all anywhere in the NUT muxer
ods15
parents: 3004
diff changeset
571 nut->max_distance = MAX_DISTANCE;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
572 build_elision_headers(s);
2329
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
573 build_frame_code(s);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
574 assert(nut->frame_code['N'].flags == FLAG_INVALID);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
575
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
576 put_buffer(bc, ID_STRING, strlen(ID_STRING));
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
577 put_byte(bc, 0);
57a352c5b051 move main header writing into its own function
michael
parents: 2328
diff changeset
578
6073
b9ddee1ca18c Make write_header() and write_header() return an error code in case of
stefano
parents: 6072
diff changeset
579 if ((ret = write_headers(s, bc)) < 0)
b9ddee1ca18c Make write_header() and write_header() return an error code in case of
stefano
parents: 6072
diff changeset
580 return ret;
2325
2829faf72879 write stream headers
michael
parents: 2324
diff changeset
581
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
582 put_flush_packet(bc);
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
583
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
584 //FIXME index
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
585
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
586 return 0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
587 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
588
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
589 static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
590 int flags= 0;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
591
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
592 if(pkt->flags & AV_PKT_FLAG_KEY ) flags |= FLAG_KEY;
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
593 if(pkt->stream_index != fc->stream_id ) flags |= FLAG_STREAM_ID;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
594 if(pkt->size / fc->size_mul ) flags |= FLAG_SIZE_MSB;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
595 if(pkt->pts - nus->last_pts != fc->pts_delta) flags |= FLAG_CODED_PTS;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
596 if(pkt->size > 2*nut->max_distance ) flags |= FLAG_CHECKSUM;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
597 if(FFABS(pkt->pts - nus->last_pts)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
598 > nus->max_pts_distance) flags |= FLAG_CHECKSUM;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
599 if( pkt->size < nut->header_len[fc->header_idx]
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
600 || (pkt->size > 4096 && fc->header_idx)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
601 || memcmp(pkt->data, nut->header[fc->header_idx], nut->header_len[fc->header_idx]))
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
602 flags |= FLAG_HEADER_IDX;
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
603
2371
253901bf60b7 do not remove FLAG_CODED
michael
parents: 2370
diff changeset
604 return flags | (fc->flags & FLAG_CODED);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
605 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
606
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
607 static int find_best_header_idx(NUTContext *nut, AVPacket *pkt){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
608 int i;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
609 int best_i = 0;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
610 int best_len= 0;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
611
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
612 if(pkt->size > 4096)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
613 return 0;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
614
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
615 for(i=1; i<nut->header_count; i++){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
616 if( pkt->size >= nut->header_len[i]
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
617 && nut->header_len[i] > best_len
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
618 && !memcmp(pkt->data, nut->header[i], nut->header_len[i])){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
619 best_i= i;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
620 best_len= nut->header_len[i];
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
621 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
622 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
623 return best_i;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
624 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
625
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
626 static int write_packet(AVFormatContext *s, AVPacket *pkt){
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
627 NUTContext *nut = s->priv_data;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
628 StreamContext *nus= &nut->stream[pkt->stream_index];
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
629 ByteIOContext *bc = s->pb, *dyn_bc;
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
630 FrameCode *fc;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
631 int64_t coded_pts;
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
632 int best_length, frame_code, flags, needed_flags, i, header_idx, best_header_idx;
5913
11bb10c37225 Replace all occurences of PKT_FLAG_KEY with AV_PKT_FLAG_KEY.
cehoyos
parents: 5910
diff changeset
633 int key_frame = !!(pkt->flags & AV_PKT_FLAG_KEY);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
634 int store_sp=0;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
635 int ret;
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
636
3508
834b97115722 Prevent invalid timestamps from being stored.
michael
parents: 3424
diff changeset
637 if(pkt->pts < 0)
834b97115722 Prevent invalid timestamps from being stored.
michael
parents: 3424
diff changeset
638 return -1;
834b97115722 Prevent invalid timestamps from being stored.
michael
parents: 3424
diff changeset
639
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
640 if(1LL<<(20+3*nut->header_count) <= url_ftell(bc))
6072
0475ccdb762d Make write_streamheader() and write_headers() accept an
stefano
parents: 6038
diff changeset
641 write_headers(s, bc);
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
642
3015
db8d14740060 Fix intented algo in syncpoint writing before keyframes in NUT muxer
ods15
parents: 3014
diff changeset
643 if(key_frame && !(nus->last_flags & FLAG_KEY))
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
644 store_sp= 1;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
645
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
646 if(pkt->size + 30/*FIXME check*/ + url_ftell(bc) >= nut->last_syncpoint_pos + nut->max_distance)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
647 store_sp= 1;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
648
2393
fc685315d568 spelling/wording cosmetics
diego
parents: 2372
diff changeset
649 //FIXME: Ensure store_sp is 1 in the first place.
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
650
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
651 if(store_sp){
4076
a5c615b9d8ec remove _t for POSIX compatibility.
michael
parents: 3766
diff changeset
652 Syncpoint *sp, dummy= {.pos= INT64_MAX};
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
653
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
654 ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
655 for(i=0; i<s->nb_streams; i++){
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
656 AVStream *st= s->streams[i];
3016
eac2648449a5 back_ptr calculation used wrong timebase when searching for back syncpoint
ods15
parents: 3015
diff changeset
657 int64_t dts_tb = av_rescale_rnd(pkt->dts,
eac2648449a5 back_ptr calculation used wrong timebase when searching for back syncpoint
ods15
parents: 3015
diff changeset
658 nus->time_base->num * (int64_t)nut->stream[i].time_base->den,
eac2648449a5 back_ptr calculation used wrong timebase when searching for back syncpoint
ods15
parents: 3015
diff changeset
659 nus->time_base->den * (int64_t)nut->stream[i].time_base->num,
eac2648449a5 back_ptr calculation used wrong timebase when searching for back syncpoint
ods15
parents: 3015
diff changeset
660 AV_ROUND_DOWN);
eac2648449a5 back_ptr calculation used wrong timebase when searching for back syncpoint
ods15
parents: 3015
diff changeset
661 int index= av_index_search_timestamp(st, dts_tb, AVSEEK_FLAG_BACKWARD);
2939
7e246e837176 Consider initial EOR in the back_ptr calculation.
michael
parents: 2771
diff changeset
662 if(index>=0) dummy.pos= FFMIN(dummy.pos, st->index_entries[index].pos);
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
663 }
2939
7e246e837176 Consider initial EOR in the back_ptr calculation.
michael
parents: 2771
diff changeset
664 if(dummy.pos == INT64_MAX)
7e246e837176 Consider initial EOR in the back_ptr calculation.
michael
parents: 2771
diff changeset
665 dummy.pos= 0;
5902
dbbcecb1a0dd Fix NUT (de)muxer warnings:
vitor
parents: 5738
diff changeset
666 sp= av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp,
dbbcecb1a0dd Fix NUT (de)muxer warnings:
vitor
parents: 5738
diff changeset
667 NULL);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
668
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
669 nut->last_syncpoint_pos= url_ftell(bc);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
670 ret = url_open_dyn_buf(&dyn_bc);
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
671 if(ret < 0)
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
672 return ret;
4076
a5c615b9d8ec remove _t for POSIX compatibility.
michael
parents: 3766
diff changeset
673 put_tt(nut, nus, dyn_bc, pkt->dts);
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
674 ff_put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos)>>4 : 0);
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
675 put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
676
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
677 ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0/*unused*/, pkt->dts);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
678 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
679 assert(nus->last_pts != AV_NOPTS_VALUE);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
680
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
681 coded_pts = pkt->pts & ((1<<nus->msb_pts_shift)-1);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
682 if(ff_lsb2full(nus, coded_pts) != pkt->pts)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
683 coded_pts= pkt->pts + (1<<nus->msb_pts_shift);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
684
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
685 best_header_idx= find_best_header_idx(nut, pkt);
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
686
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
687 best_length=INT_MAX;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
688 frame_code= -1;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
689 for(i=0; i<256; i++){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
690 int length= 0;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
691 FrameCode *fc= &nut->frame_code[i];
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
692 int flags= fc->flags;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
693
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
694 if(flags & FLAG_INVALID)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
695 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
696 needed_flags= get_needed_flags(nut, nus, fc, pkt);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
697
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
698 if(flags & FLAG_CODED){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
699 length++;
2372
5c3d8e112e79 simplify
michael
parents: 2371
diff changeset
700 flags = needed_flags;
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
701 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
702
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
703 if((flags & needed_flags) != needed_flags)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
704 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
705
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
706 if((flags ^ needed_flags) & FLAG_KEY)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
707 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
708
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
709 if(flags & FLAG_STREAM_ID)
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
710 length+= ff_get_v_length(pkt->stream_index);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
711
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
712 if(pkt->size % fc->size_mul != fc->size_lsb)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
713 continue;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
714 if(flags & FLAG_SIZE_MSB)
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
715 length += ff_get_v_length(pkt->size / fc->size_mul);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
716
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
717 if(flags & FLAG_CHECKSUM)
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
718 length+=4;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
719
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
720 if(flags & FLAG_CODED_PTS)
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
721 length += ff_get_v_length(coded_pts);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
722
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
723 if( (flags & FLAG_CODED)
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
724 && nut->header_len[best_header_idx] > nut->header_len[fc->header_idx]+1){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
725 flags |= FLAG_HEADER_IDX;
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
726 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
727
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
728 if(flags & FLAG_HEADER_IDX){
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
729 length += 1 - nut->header_len[best_header_idx];
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
730 }else{
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
731 length -= nut->header_len[fc->header_idx];
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
732 }
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
733
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
734 length*=4;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
735 length+= !(flags & FLAG_CODED_PTS);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
736 length+= !(flags & FLAG_CHECKSUM);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
737
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
738 if(length < best_length){
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
739 best_length= length;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
740 frame_code=i;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
741 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
742 }
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
743 assert(frame_code != -1);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
744 fc= &nut->frame_code[frame_code];
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
745 flags= fc->flags;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
746 needed_flags= get_needed_flags(nut, nus, fc, pkt);
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
747 header_idx= fc->header_idx;
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
748
2683
153d6efc05b8 rename av_crc04C11DB7_update to ff_crc04C11DB7_update and move it to aviobuf.c so it can be reused by other (de)muxers
bcoudurier
parents: 2393
diff changeset
749 init_checksum(bc, ff_crc04C11DB7_update, 0);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
750 put_byte(bc, frame_code);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
751 if(flags & FLAG_CODED){
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
752 ff_put_v(bc, (flags^needed_flags) & ~(FLAG_CODED));
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
753 flags = needed_flags;
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
754 }
6245
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
755 if(flags & FLAG_STREAM_ID) ff_put_v(bc, pkt->stream_index);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
756 if(flags & FLAG_CODED_PTS) ff_put_v(bc, coded_pts);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
757 if(flags & FLAG_SIZE_MSB) ff_put_v(bc, pkt->size / fc->size_mul);
ef4606cc4fb3 rename get_length to ff_get_v_length and put_v to ff_put_v
janne
parents: 6199
diff changeset
758 if(flags & FLAG_HEADER_IDX) ff_put_v(bc, header_idx= best_header_idx);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
759
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
760 if(flags & FLAG_CHECKSUM) put_le32(bc, get_checksum(bc));
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
761 else get_checksum(bc);
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
762
3046
c12367fe98ad Header elision muxing support.
michael
parents: 3016
diff changeset
763 put_buffer(bc, pkt->data + nut->header_len[header_idx], pkt->size - nut->header_len[header_idx]);
2343
c6a7a89a0cef write frames and syncpoints
michael
parents: 2342
diff changeset
764 nus->last_flags= flags;
3047
3c374f48768d It appears last_pts was not set ...
michael
parents: 3046
diff changeset
765 nus->last_pts= pkt->pts;
2350
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
766
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
767 //FIXME just store one per syncpoint
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
768 if(flags & FLAG_KEY)
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
769 av_add_index_entry(
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
770 s->streams[pkt->stream_index],
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
771 nut->last_syncpoint_pos,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
772 pkt->pts,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
773 0,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
774 0,
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
775 AVINDEX_KEYFRAME);
a0fb5ef1ec7c set back ptr properly
michael
parents: 2347
diff changeset
776
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
777 return 0;
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
778 }
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
779
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
780 static int write_trailer(AVFormatContext *s){
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
781 NUTContext *nut= s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2683
diff changeset
782 ByteIOContext *bc= s->pb;
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
783
2359
1860d5b4be2e header repetition
michael
parents: 2358
diff changeset
784 while(nut->header_count<3)
6072
0475ccdb762d Make write_streamheader() and write_headers() accept an
stefano
parents: 6038
diff changeset
785 write_headers(s, bc);
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
786 put_flush_packet(bc);
5738
7152149eb03f Plug memory leak in NUT muxer and demuxer
vitor
parents: 5733
diff changeset
787 ff_nut_free_sp(nut);
5729
aef0883e3445 Plug some memory leaks in NUT muxer and demuxer
vitor
parents: 5704
diff changeset
788 av_freep(&nut->stream);
aef0883e3445 Plug some memory leaks in NUT muxer and demuxer
vitor
parents: 5704
diff changeset
789 av_freep(&nut->time_base);
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
790
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
791 return 0;
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
792 }
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
793
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
794 AVOutputFormat nut_muxer = {
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
795 "nut",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3286
diff changeset
796 NULL_IF_CONFIG_SMALL("NUT format"),
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
797 "video/x-nut",
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
798 "nut",
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
799 sizeof(NUTContext),
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4201
diff changeset
800 #if CONFIG_LIBVORBIS
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
801 CODEC_ID_VORBIS,
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 4201
diff changeset
802 #elif CONFIG_LIBMP3LAME
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
803 CODEC_ID_MP3,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
804 #else
3623
e5b79592e187 remove a comment which is no longer true
jbr
parents: 3508
diff changeset
805 CODEC_ID_MP2,
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
806 #endif
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
807 CODEC_ID_MPEG4,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
808 write_header,
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
809 write_packet,
2346
cbcd840cf971 store headers twice (getting closer to spec compliance ...)
michael
parents: 2345
diff changeset
810 write_trailer,
4567
963e3b76c7a6 Add AVFMT_VARIABLE_FPS to specify which muxers do not need duplicated frames.
michael
parents: 4520
diff changeset
811 .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
6038
d0ea87d82842 Define ff_nut_video_tags and make Nut muxer and demuxer set it in
stefano
parents: 6033
diff changeset
812 .codec_tag = (const AVCodecTag * const []){ ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 },
5704
6b9c2a6d8fa4 Introduce metadata conversion table for NUT muxer and demuxer.
kostya
parents: 5058
diff changeset
813 .metadata_conv = ff_nut_metadata_conv,
2324
919efc8760a0 trying to finally get the nut muxer back uptodate
michael
parents:
diff changeset
814 };