1 /*
2 * NUT (de)muxing via libnut
3 * copyright (c) 2006 Oded Shimon <ods15@ods15.dyndns.org>
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * NUT demuxing and muxing via libnut.
25 * @author Oded Shimon <ods15@ods15.dyndns.org>
26 */
27
31 #include <libnut.h>
32
33 #define ID_STRING "nut/multimedia container"
34 #define ID_LENGTH (strlen(ID_STRING) + 1)
35
38 nut_stream_header_tt *
s;
40
45 { 0, 0 },
46 };
47
48 #if CONFIG_LIBNUT_MUXER
49 static int av_write(
void * h,
size_t len,
const uint8_t *
buf) {
52 //avio_flush(bc);
54 }
55
59 nut_muxer_opts_tt mopts = {
60 .output = {
61 .priv = bc,
62 .write = av_write,
63 },
65 .write_index = 1,
66 .realtime_stream = 0,
67 .max_distance = 32768,
68 .fti = NULL,
69 };
70 nut_stream_header_tt *
s;
71 int i;
72
74 if(!s)
76
79 int j;
80 int fourcc = 0;
81 int num, denom, ssize;
82
84
87
88 if (!fourcc) {
91 }
92
93 s[i].fourcc_len = 4;
95 for (j = 0; j < s[i].fourcc_len; j++) s[i].fourcc[j] = (fourcc >> (j*8)) & 0xFF;
96
99
100 s[i].time_base.num = denom;
101 s[i].time_base.den = num;
102
103 s[i].fixed_fps = 0;
107
109 s[i].width = codec->
width;
110 s[i].height = codec->
height;
111 s[i].sample_width = 0;
112 s[i].sample_height = 0;
113 s[i].colorspace_type = 0;
114 } else {
116 s[i].samplerate_denom = 1;
117 s[i].channel_count = codec->
channels;
118 }
119 }
120
122 priv->
nut = nut_muxer_init(&mopts, s, NULL);
123
124 return 0;
125 }
126
129 nut_packet_tt p;
130
135 p.next_pts = 0;
136
137 nut_write_frame_reorder(priv->
nut, &p, pkt->
data);
138
139 return 0;
140 }
141
145 int i;
146
147 nut_muxer_uninit_reorder(priv->
nut);
149
150 for(i = 0; priv->
s[i].type != -1; i++ )
av_freep(&priv->
s[i].fourcc);
152
153 return 0;
154 }
155
158 .long_name = "nut format",
159 .mime_type = "video/x-nut",
160 .extensions = "nut",
168 };
169 #endif /* CONFIG_LIBNUT_MUXER */
170
173
174 return 0;
175 }
176
180 }
181
182 static off_t
av_seek(
void * h,
long long pos,
int whence) {
184 if (whence == SEEK_END) {
186 whence = SEEK_SET;
187 }
189 }
190
194 nut_demuxer_opts_tt dopts = {
195 .input = {
196 .priv = bc,
199 .eof = NULL,
200 .file_pos = 0,
201 },
203 .read_index = 1,
204 .cache_syncpoints = 1,
205 };
206 nut_context_tt * nut = priv->
nut = nut_demuxer_init(&dopts);
207 nut_stream_header_tt *
s;
209
210 if(!nut)
211 return -1;
212
213 if ((ret = nut_read_headers(nut, &s, NULL))) {
215 nut_demuxer_uninit(nut);
217 return -1;
218 }
219
221
222 for (i = 0; s[i].type != -1 && i < 2; i++) {
224 int j;
225
226 if (!st)
228
229 for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->
codec->
codec_tag |= s[i].fourcc[j]<<(j*8);
230
232
236 nut_demuxer_uninit(nut);
239 }
241 }
242
246
248
250 case NUT_AUDIO_CLASS:
253
256 break;
257 case NUT_VIDEO_CLASS:
260
265 break;
266 }
268 }
269
270 return 0;
271 }
272
275 nut_packet_tt pd;
277
278 ret = nut_read_next_packet(priv->
nut, &pd);
279
281 if (ret != NUT_ERR_EOF)
283 return -1;
284 }
285
290
291 ret = nut_read_frame(priv->
nut, &pd.len, pkt->
data);
292
294 }
295
298 int active_streams[] = { stream_index, -1 };
299 double time_pos = target_ts * priv->
s[stream_index].time_base.num / (double)priv->
s[stream_index].time_base.den;
300
302
303 return 0;
304 }
305
308
309 nut_demuxer_uninit(priv->
nut);
310
311 return 0;
312 }
313
323 .extensions = "nut",
324 };