Mercurial > libavformat.hg
annotate libnut.c @ 2660:022174d849d5 libavformat
fix issue 225, instead of stoping when wrong atom size is found,
limit atom size to what is left, assuming container atom has correct size..
cricket4.3g2 has incorrect moov atom size which indicates that file size should be
2 bytes bigger than it is and quicktime reads it correctly though.
author | bcoudurier |
---|---|
date | Mon, 22 Oct 2007 14:36:14 +0000 |
parents | ce70d4ec9e3a |
children | 53b9a531f490 |
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 | |
1892 | 22 /** |
23 * @file libnut.c | |
24 * NUT demuxing and muxing via libnut. | |
25 * @author Oded Shimon <ods15@ods15.dyndns.org> | |
26 */ | |
27 | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
28 #include "avformat.h" |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
29 #include "riff.h" |
1499 | 30 #include <libnut.h> |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
31 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
32 #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
|
33 #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
|
34 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
35 typedef struct { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
36 nut_context_t * nut; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
37 nut_stream_header_t * s; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
38 } NUTContext; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
39 |
1677
2a85c82b8538
add codec_id <-> codec_tag tables to AVIn/OutputFormat
michael
parents:
1600
diff
changeset
|
40 static const AVCodecTag nut_tags[] = { |
1525 | 41 { 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
|
42 { 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
|
43 { 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
|
44 { 0, 0 }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
45 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
46 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
47 #ifdef CONFIG_MUXERS |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
48 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
|
49 ByteIOContext * bc = h; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
50 put_buffer(bc, buf, len); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
51 //put_flush_packet(bc); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
52 return len; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
53 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
54 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
55 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
|
56 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
57 ByteIOContext * bc = &avf->pb; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
58 nut_muxer_opts_t mopts = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
59 .output = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
60 .priv = bc, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
61 .write = av_write, |
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 .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
|
64 .write_index = 1, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
65 .realtime_stream = 0, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
66 .max_distance = 32768, |
1524 | 67 .fti = NULL, |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
68 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
69 nut_stream_header_t * s; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
70 int i; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
71 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
72 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
|
73 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
74 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
|
75 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
|
76 int j; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
77 int fourcc = 0; |
1600 | 78 int num, denom, ssize; |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
79 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
80 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
|
81 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
82 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
|
83 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
|
84 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
85 if (!fourcc) { |
1893
7460077180aa
remove usage of deprecated functions in libnut.c (codec_get_id/tag)
ods15
parents:
1892
diff
changeset
|
86 if (codec->codec_type == CODEC_TYPE_VIDEO) fourcc = codec_get_tag(codec_bmp_tags, codec->codec_id); |
7460077180aa
remove usage of deprecated functions in libnut.c (codec_get_id/tag)
ods15
parents:
1892
diff
changeset
|
87 if (codec->codec_type == CODEC_TYPE_AUDIO) fourcc = codec_get_tag(codec_wav_tags, codec->codec_id); |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
88 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
89 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
90 s[i].fourcc_len = 4; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
91 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
|
92 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
|
93 |
1600 | 94 ff_parse_specific_params(codec, &num, &ssize, &denom); |
95 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
|
96 |
1600 | 97 s[i].time_base.num = denom; |
98 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
|
99 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
100 s[i].fixed_fps = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
101 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
|
102 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
|
103 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
|
104 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
105 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
|
106 s[i].width = codec->width; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
107 s[i].height = codec->height; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
108 s[i].sample_width = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
109 s[i].sample_height = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
110 s[i].colorspace_type = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
111 } else { |
1600 | 112 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
|
113 s[i].samplerate_denom = 1; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
114 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
|
115 } |
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 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
|
119 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
|
120 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
121 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
122 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
123 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
124 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
|
125 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
126 nut_packet_t p; |
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 p.len = pkt->size; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
129 p.stream = pkt->stream_index; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
130 p.pts = pkt->pts; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
131 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
|
132 p.next_pts = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
133 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
134 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
|
135 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
136 return 0; |
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 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
139 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
|
140 ByteIOContext * bc = &avf->pb; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
141 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
142 int i; |
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 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
|
145 put_flush_packet(bc); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
146 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
147 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
|
148 av_freep(&priv->s); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
149 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
150 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
151 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
152 |
1769 | 153 AVOutputFormat libnut_muxer = { |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
154 "nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
155 "nut format", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
156 "video/x-nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
157 "nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
158 sizeof(NUTContext), |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
159 CODEC_ID_VORBIS, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
160 CODEC_ID_MPEG4, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
161 nut_write_header, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
162 nut_write_packet, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
163 nut_write_trailer, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
164 .flags = AVFMT_GLOBALHEADER, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
165 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
166 #endif //CONFIG_MUXERS |
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 int nut_probe(AVProbeData *p) { |
2001
1a3c9056982a
allocate 32 extra bytes at the end of the probe buffer and remove most probe buf_size checks
michael
parents:
1893
diff
changeset
|
169 if (!memcmp(p->buf, ID_STRING, ID_LENGTH)) return AVPROBE_SCORE_MAX; |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
170 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
171 return 0; |
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 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
174 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
|
175 ByteIOContext * bc = h; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
176 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
|
177 } |
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 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
|
180 ByteIOContext * bc = h; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
181 if (whence == SEEK_END) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
182 pos = url_fsize(bc) + pos; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
183 whence = SEEK_SET; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
184 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
185 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
|
186 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
187 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
188 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
|
189 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
190 ByteIOContext * bc = &avf->pb; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
191 nut_demuxer_opts_t dopts = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
192 .input = { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
193 .priv = bc, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
194 .seek = av_seek, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
195 .read = av_read, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
196 .eof = NULL, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
197 .file_pos = 0, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
198 }, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
199 .alloc = { av_malloc, av_realloc, av_free }, |
1505 | 200 .read_index = 1, |
201 .cache_syncpoints = 1, | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
202 }; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
203 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
|
204 nut_stream_header_t * s; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
205 int ret, i; |
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 if ((ret = nut_read_headers(nut, &s, NULL))) { |
1513 | 208 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
|
209 nut_demuxer_uninit(nut); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
210 return -1; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
211 } |
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 priv->s = s; |
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 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
|
216 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
|
217 int j; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
218 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
219 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
|
220 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
221 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
|
222 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
223 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
|
224 if (st->codec->extradata_size) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
225 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
|
226 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
|
227 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
228 |
1600 | 229 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
|
230 st->start_time = 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
231 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
|
232 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
233 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
|
234 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
235 switch(s[i].type) { |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
236 case NUT_AUDIO_CLASS: |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
237 st->codec->codec_type = CODEC_TYPE_AUDIO; |
1893
7460077180aa
remove usage of deprecated functions in libnut.c (codec_get_id/tag)
ods15
parents:
1892
diff
changeset
|
238 if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_id(codec_wav_tags, st->codec->codec_tag); |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
239 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
240 st->codec->channels = s[i].channel_count; |
1600 | 241 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
|
242 break; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
243 case NUT_VIDEO_CLASS: |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
244 st->codec->codec_type = CODEC_TYPE_VIDEO; |
1893
7460077180aa
remove usage of deprecated functions in libnut.c (codec_get_id/tag)
ods15
parents:
1892
diff
changeset
|
245 if (st->codec->codec_id == CODEC_ID_NONE) st->codec->codec_id = codec_get_id(codec_bmp_tags, st->codec->codec_tag); |
1482
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 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
|
248 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
|
249 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
|
250 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
|
251 break; |
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 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
|
254 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
255 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
256 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
257 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
258 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
259 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
|
260 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
261 nut_packet_t pd; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
262 int ret; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
263 |
1513 | 264 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
|
265 |
1513 | 266 if (ret || av_new_packet(pkt, pd.len) < 0) { |
267 if (ret != NUT_ERR_EOF) | |
268 av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret)); | |
269 return -1; | |
270 } | |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
271 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
272 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
|
273 pkt->pts = pd.pts; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
274 pkt->stream_index = pd.stream; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
275 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
|
276 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
277 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
|
278 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
279 return ret; |
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 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
282 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
|
283 NUTContext * priv = avf->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
284 int active_streams[] = { stream_index, -1 }; |
1600 | 285 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
|
286 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
287 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
|
288 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
289 return 0; |
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 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
292 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
|
293 NUTContext * priv = s->priv_data; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
294 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
295 nut_demuxer_uninit(priv->nut); |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
296 |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
297 return 0; |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
298 } |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
299 |
1769 | 300 AVInputFormat libnut_demuxer = { |
2528
ce70d4ec9e3a
Prefix library format names with 'lib' in libavformat
ramiro
parents:
2001
diff
changeset
|
301 "libnut", |
1482
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
302 "nut format", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
303 sizeof(NUTContext), |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
304 nut_probe, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
305 nut_read_header, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
306 nut_read_packet, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
307 nut_read_close, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
308 nut_read_seek, |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
309 .extensions = "nut", |
617beb4c6247
Add libnut support until ffmpeg gets an independant and complete de/muxer for NUT
ods15
parents:
diff
changeset
|
310 }; |