Mercurial > libavformat.hg
annotate libnut.c @ 1848:ffa08e7f7c88 libavformat
try to move fixed mov.c over the one with cosmetic-functional mix
author | michael |
---|---|
date | Sat, 03 Mar 2007 21:14:10 +0000 |
parents | 27ae0787cc6c |
children | cf0c623c627a |
rev | line source |
---|---|
1816 | 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 | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
22 #include "avformat.h" |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
23 #include "riff.h" |
1499 | 24 #include <libnut.h> |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
25 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
26 #define ID_STRING "nut/multimedia container" |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
27 #define ID_LENGTH (strlen(ID_STRING) + 1) |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
28 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
29 typedef struct { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
30 nut_context_t * nut; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
31 nut_stream_header_t * s; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
32 } NUTContext; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
33 |
1677
2a85c82b8538
add codec_id <-> codec_tag tables to AVIn/OutputFormat
michael
parents:
1600
diff
changeset
|
34 static const AVCodecTag nut_tags[] = { |
1525 | 35 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') }, |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
36 { CODEC_ID_MP3, MKTAG('m', 'p', '3', ' ') }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
37 { CODEC_ID_VORBIS, MKTAG('v', 'r', 'b', 's') }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
38 { 0, 0 }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
39 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
40 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
41 #ifdef CONFIG_MUXERS |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
42 static int av_write(void * h, size_t len, const uint8_t * buf) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
43 ByteIOContext * bc = h; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
44 put_buffer(bc, buf, len); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
45 //put_flush_packet(bc); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
46 return len; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
47 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
48 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
49 static int nut_write_header(AVFormatContext * avf) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
50 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
51 ByteIOContext * bc = &avf->pb; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
52 nut_muxer_opts_t mopts = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
53 .output = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
54 .priv = bc, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
55 .write = av_write, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
56 }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
57 .alloc = { av_malloc, av_realloc, av_free }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
58 .write_index = 1, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
59 .realtime_stream = 0, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
60 .max_distance = 32768, |
1524 | 61 .fti = NULL, |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
62 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
63 nut_stream_header_t * s; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
64 int i; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
65 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
66 priv->s = s = av_mallocz((avf->nb_streams + 1) * sizeof*s); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
67 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
68 for (i = 0; i < avf->nb_streams; i++) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
69 AVCodecContext * codec = avf->streams[i]->codec; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
70 int j; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
71 int fourcc = 0; |
1600 | 72 int num, denom, ssize; |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
73 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
74 s[i].type = codec->codec_type == CODEC_TYPE_VIDEO ? NUT_VIDEO_CLASS : NUT_AUDIO_CLASS; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
75 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
76 if (codec->codec_tag) fourcc = codec->codec_tag; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
77 else fourcc = codec_get_tag(nut_tags, codec->codec_id); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
78 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
79 if (!fourcc) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
80 if (codec->codec_type == CODEC_TYPE_VIDEO) fourcc = codec_get_bmp_tag(codec->codec_id); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
81 if (codec->codec_type == CODEC_TYPE_AUDIO) fourcc = codec_get_wav_tag(codec->codec_id); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
82 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
83 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
84 s[i].fourcc_len = 4; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
85 s[i].fourcc = av_malloc(s[i].fourcc_len); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
86 for (j = 0; j < s[i].fourcc_len; j++) s[i].fourcc[j] = (fourcc >> (j*8)) & 0xFF; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
87 |
1600 | 88 ff_parse_specific_params(codec, &num, &ssize, &denom); |
89 av_set_pts_info(avf->streams[i], 60, denom, num); | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
90 |
1600 | 91 s[i].time_base.num = denom; |
92 s[i].time_base.den = num; | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
93 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
94 s[i].fixed_fps = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
95 s[i].decode_delay = codec->has_b_frames; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
96 s[i].codec_specific_len = codec->extradata_size; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
97 s[i].codec_specific = codec->extradata; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
98 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
99 if (codec->codec_type == CODEC_TYPE_VIDEO) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
100 s[i].width = codec->width; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
101 s[i].height = codec->height; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
102 s[i].sample_width = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
103 s[i].sample_height = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
104 s[i].colorspace_type = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
105 } else { |
1600 | 106 s[i].samplerate_num = codec->sample_rate; |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
107 s[i].samplerate_denom = 1; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
108 s[i].channel_count = codec->channels; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
109 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
110 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
111 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
112 s[avf->nb_streams].type = -1; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
113 priv->nut = nut_muxer_init(&mopts, s, NULL); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
114 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
115 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
116 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
117 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
118 static int nut_write_packet(AVFormatContext * avf, AVPacket * pkt) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
119 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
120 nut_packet_t p; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
121 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
122 p.len = pkt->size; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
123 p.stream = pkt->stream_index; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
124 p.pts = pkt->pts; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
125 p.flags = pkt->flags & PKT_FLAG_KEY ? NUT_FLAG_KEY : 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
126 p.next_pts = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
127 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
128 nut_write_frame_reorder(priv->nut, &p, pkt->data); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
129 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
130 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
131 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
132 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
133 static int nut_write_trailer(AVFormatContext * avf) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
134 ByteIOContext * bc = &avf->pb; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
135 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
136 int i; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
137 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
138 nut_muxer_uninit_reorder(priv->nut); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
139 put_flush_packet(bc); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
140 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
141 for(i = 0; priv->s[i].type != -1; i++ ) av_freep(&priv->s[i].fourcc); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
142 av_freep(&priv->s); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
143 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
144 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
145 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
146 |
1769 | 147 AVOutputFormat libnut_muxer = { |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
148 "nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
149 "nut format", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
150 "video/x-nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
151 "nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
152 sizeof(NUTContext), |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
153 CODEC_ID_VORBIS, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
154 CODEC_ID_MPEG4, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
155 nut_write_header, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
156 nut_write_packet, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
157 nut_write_trailer, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
158 .flags = AVFMT_GLOBALHEADER, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
159 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
160 #endif //CONFIG_MUXERS |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
161 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
162 static int nut_probe(AVProbeData *p) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
163 if (p->buf_size >= ID_LENGTH && !memcmp(p->buf, ID_STRING, ID_LENGTH)) return AVPROBE_SCORE_MAX; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
164 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
165 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
166 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
167 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
168 static size_t av_read(void * h, size_t len, uint8_t * buf) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
169 ByteIOContext * bc = h; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
170 return get_buffer(bc, buf, len); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
171 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
172 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
173 static off_t av_seek(void * h, long long pos, int whence) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
174 ByteIOContext * bc = h; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
175 if (whence == SEEK_END) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
176 pos = url_fsize(bc) + pos; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
177 whence = SEEK_SET; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
178 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
179 return url_fseek(bc, pos, whence); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
180 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
181 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
182 static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
183 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
184 ByteIOContext * bc = &avf->pb; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
185 nut_demuxer_opts_t dopts = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
186 .input = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
187 .priv = bc, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
188 .seek = av_seek, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
189 .read = av_read, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
190 .eof = NULL, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
191 .file_pos = 0, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
192 }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
193 .alloc = { av_malloc, av_realloc, av_free }, |
1505 | 194 .read_index = 1, |
195 .cache_syncpoints = 1, | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
196 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
197 nut_context_t * nut = priv->nut = nut_demuxer_init(&dopts); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
198 nut_stream_header_t * s; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
199 int ret, i; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
200 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
201 if ((ret = nut_read_headers(nut, &s, NULL))) { |
1513 | 202 av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret)); |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
203 nut_demuxer_uninit(nut); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
204 return -1; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
205 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
206 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
207 priv->s = s; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
208 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
209 for (i = 0; s[i].type != -1 && i < 2; i++) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
210 AVStream * st = av_new_stream(avf, i); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
211 int j; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
212 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
213 for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codec->codec_tag |= s[i].fourcc[j]<<(j*8); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
214 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
215 st->codec->has_b_frames = s[i].decode_delay; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
216 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
217 st->codec->extradata_size = s[i].codec_specific_len; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
218 if (st->codec->extradata_size) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
219 st->codec->extradata = av_mallocz(st->codec->extradata_size); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
220 memcpy(st->codec->extradata, s[i].codec_specific, st->codec->extradata_size); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
221 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
222 |
1600 | 223 av_set_pts_info(avf->streams[i], 60, s[i].time_base.num, s[i].time_base.den); |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
224 st->start_time = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
225 st->duration = s[i].max_pts; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
226 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
227 st->codec->codec_id = codec_get_id(nut_tags, st->codec->codec_tag); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
228 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
229 switch(s[i].type) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
230 case NUT_AUDIO_CLASS: |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
231 st->codec->codec_type = CODEC_TYPE_AUDIO; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
232 if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_wav_id(st->codec->codec_tag); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
233 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
234 st->codec->channels = s[i].channel_count; |
1600 | 235 st->codec->sample_rate = s[i].samplerate_num / s[i].samplerate_denom; |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
236 break; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
237 case NUT_VIDEO_CLASS: |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
238 st->codec->codec_type = CODEC_TYPE_VIDEO; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
239 if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_bmp_id(st->codec->codec_tag); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
240 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
241 st->codec->width = s[i].width; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
242 st->codec->height = s[i].height; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
243 st->codec->sample_aspect_ratio.num = s[i].sample_width; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
244 st->codec->sample_aspect_ratio.den = s[i].sample_height; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
245 break; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
246 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
247 if (st->codec->codec_id == CODEC_ID_NONE) av_log(avf, AV_LOG_ERROR, "Unknown codec?!\n"); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
248 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
249 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
250 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
251 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
252 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
253 static int nut_read_packet(AVFormatContext * avf, AVPacket * pkt) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
254 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
255 nut_packet_t pd; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
256 int ret; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
257 |
1513 | 258 ret = nut_read_next_packet(priv->nut, &pd); |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
259 |
1513 | 260 if (ret || av_new_packet(pkt, pd.len) < 0) { |
261 if (ret != NUT_ERR_EOF) | |
262 av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret)); | |
263 return -1; | |
264 } | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
265 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
266 if (pd.flags & NUT_FLAG_KEY) pkt->flags |= PKT_FLAG_KEY; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
267 pkt->pts = pd.pts; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
268 pkt->stream_index = pd.stream; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
269 pkt->pos = url_ftell(&avf->pb); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
270 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
271 ret = nut_read_frame(priv->nut, &pd.len, pkt->data); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
272 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
273 return ret; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
274 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
275 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
276 static int nut_read_seek(AVFormatContext * avf, int stream_index, int64_t target_ts, int flags) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
277 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
278 int active_streams[] = { stream_index, -1 }; |
1600 | 279 double time_pos = target_ts * priv->s[stream_index].time_base.num / (double)priv->s[stream_index].time_base.den; |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
280 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
281 if (nut_seek(priv->nut, time_pos, 2*!(flags & AVSEEK_FLAG_BACKWARD), active_streams)) return -1; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
282 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
283 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
284 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
285 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
286 static int nut_read_close(AVFormatContext *s) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
287 NUTContext * priv = s->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
288 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
289 nut_demuxer_uninit(priv->nut); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
290 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
291 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
292 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
293 |
1769 | 294 AVInputFormat libnut_demuxer = { |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
295 "nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
296 "nut format", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
297 sizeof(NUTContext), |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
298 nut_probe, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
299 nut_read_header, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
300 nut_read_packet, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
301 nut_read_close, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
302 nut_read_seek, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
303 .extensions = "nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
304 }; |