Statistics
| Branch: | Revision:

ffmpeg / libavformat / rawdec.c @ b3db9cee

History | View | Annotate | Download (6.29 KB)

1 115329f1 Diego Biurrun
/*
2 4ca31edc Aurelien Jacobs
 * RAW demuxers
3 406792e7 Diego Biurrun
 * Copyright (c) 2001 Fabrice Bellard
4 84c63c01 Alex Beregszaszi
 * Copyright (c) 2005 Alex Beregszaszi
5 de6d9b64 Fabrice Bellard
 *
6 b78e7197 Diego Biurrun
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9 19720f15 Fabrice Bellard
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11 b78e7197 Diego Biurrun
 * version 2.1 of the License, or (at your option) any later version.
12 de6d9b64 Fabrice Bellard
 *
13 b78e7197 Diego Biurrun
 * FFmpeg is distributed in the hope that it will be useful,
14 de6d9b64 Fabrice Bellard
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 19720f15 Fabrice Bellard
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17 de6d9b64 Fabrice Bellard
 *
18 19720f15 Fabrice Bellard
 * You should have received a copy of the GNU Lesser General Public
19 b78e7197 Diego Biurrun
 * License along with FFmpeg; if not, write to the Free Software
20 5509bffa Diego Biurrun
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 de6d9b64 Fabrice Bellard
 */
22 245976da Diego Biurrun
23 de6d9b64 Fabrice Bellard
#include "avformat.h"
24 b3db9cee Anton Khirnov
#include "avio_internal.h"
25 4ca31edc Aurelien Jacobs
#include "rawdec.h"
26 de6d9b64 Fabrice Bellard
27
/* raw input */
28 e94204df Aurelien Jacobs
int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
29 de6d9b64 Fabrice Bellard
{
30
    AVStream *st;
31 0f87b771 Carl Eugen Hoyos
    enum CodecID id;
32 de6d9b64 Fabrice Bellard
33 c9a65ca8 Fabrice Bellard
    st = av_new_stream(s, 0);
34 de6d9b64 Fabrice Bellard
    if (!st)
35 769e10f0 Panagiotis Issaris
        return AVERROR(ENOMEM);
36 c04c3282 Michael Niedermayer
37 c9a65ca8 Fabrice Bellard
        id = s->iformat->value;
38
        if (id == CODEC_ID_RAWVIDEO) {
39 72415b2a Stefano Sabatini
            st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
40 de6d9b64 Fabrice Bellard
        } else {
41 72415b2a Stefano Sabatini
            st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
42 de6d9b64 Fabrice Bellard
        }
43 01f4895c Michael Niedermayer
        st->codec->codec_id = id;
44 c9a65ca8 Fabrice Bellard
45 01f4895c Michael Niedermayer
        switch(st->codec->codec_type) {
46 72415b2a Stefano Sabatini
        case AVMEDIA_TYPE_AUDIO:
47 01f4895c Michael Niedermayer
            st->codec->sample_rate = ap->sample_rate;
48 bf9067cf Michael Niedermayer
            if(ap->channels) st->codec->channels = ap->channels;
49
            else             st->codec->channels = 1;
50 a3d23e15 Baptiste Coudurier
            st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
51
            assert(st->codec->bits_per_coded_sample > 0);
52
            st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
53 01f4895c Michael Niedermayer
            av_set_pts_info(st, 64, 1, st->codec->sample_rate);
54 de6d9b64 Fabrice Bellard
            break;
55 72415b2a Stefano Sabatini
        case AVMEDIA_TYPE_VIDEO:
56 9de0be61 Michael Niedermayer
            if(ap->time_base.num)
57
                av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den);
58
            else
59
                av_set_pts_info(st, 64, 1, 25);
60 01f4895c Michael Niedermayer
            st->codec->width = ap->width;
61
            st->codec->height = ap->height;
62
            st->codec->pix_fmt = ap->pix_fmt;
63
            if(st->codec->pix_fmt == PIX_FMT_NONE)
64
                st->codec->pix_fmt= PIX_FMT_YUV420P;
65 de6d9b64 Fabrice Bellard
            break;
66
        default:
67 27e084bd Fabrice Bellard
            return -1;
68 de6d9b64 Fabrice Bellard
        }
69
    return 0;
70
}
71
72 2e93e3aa Fabrice Bellard
#define RAW_PACKET_SIZE 1024
73 de6d9b64 Fabrice Bellard
74 81f052cb Justin Ruggles
int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
75 e15dec10 Leon van Stuivenberg
{
76
    int ret, size;
77
78
    size = RAW_PACKET_SIZE;
79
80
    if (av_new_packet(pkt, size) < 0)
81 c67031e7 Reimar Döffinger
        return AVERROR(ENOMEM);
82 115329f1 Diego Biurrun
83 899681cd Björn Axelsson
    pkt->pos= url_ftell(s->pb);
84 e15dec10 Leon van Stuivenberg
    pkt->stream_index = 0;
85 b3db9cee Anton Khirnov
    ret = ffio_read_partial(s->pb, pkt->data, size);
86 c3db0bc6 Reimar Döffinger
    if (ret < 0) {
87 e15dec10 Leon van Stuivenberg
        av_free_packet(pkt);
88 c3db0bc6 Reimar Döffinger
        return ret;
89 e15dec10 Leon van Stuivenberg
    }
90
    pkt->size = ret;
91
    return ret;
92
}
93 76d32428 Diego Biurrun
94 6d0678d1 Aurelien Jacobs
int ff_raw_audio_read_header(AVFormatContext *s,
95 a0af2fa4 Baptiste Coudurier
                             AVFormatParameters *ap)
96 fda885c7 Måns Rullgård
{
97 a0af2fa4 Baptiste Coudurier
    AVStream *st = av_new_stream(s, 0);
98 fda885c7 Måns Rullgård
    if (!st)
99 769e10f0 Panagiotis Issaris
        return AVERROR(ENOMEM);
100 72415b2a Stefano Sabatini
    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
101 a0af2fa4 Baptiste Coudurier
    st->codec->codec_id = s->iformat->value;
102 57004ff1 Aurelien Jacobs
    st->need_parsing = AVSTREAM_PARSE_FULL;
103 fda885c7 Måns Rullgård
    /* the parameters will be extracted from the compressed bitstream */
104 6cde949a David DeHaven
105 fda885c7 Måns Rullgård
    return 0;
106
}
107
108 fb9f1117 Diego Biurrun
/* MPEG-1/H.263 input */
109 b47a5a95 Aurelien Jacobs
int ff_raw_video_read_header(AVFormatContext *s,
110 de6d9b64 Fabrice Bellard
                             AVFormatParameters *ap)
111
{
112
    AVStream *st;
113
114 c9a65ca8 Fabrice Bellard
    st = av_new_stream(s, 0);
115 de6d9b64 Fabrice Bellard
    if (!st)
116 769e10f0 Panagiotis Issaris
        return AVERROR(ENOMEM);
117 de6d9b64 Fabrice Bellard
118 72415b2a Stefano Sabatini
    st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
119 01f4895c Michael Niedermayer
    st->codec->codec_id = s->iformat->value;
120 57004ff1 Aurelien Jacobs
    st->need_parsing = AVSTREAM_PARSE_FULL;
121 4986a429 Fabrice Bellard
122 fb9f1117 Diego Biurrun
    /* for MJPEG, specify frame rate */
123
    /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/
124 c04c3282 Michael Niedermayer
    if (ap->time_base.num) {
125 4022fe01 Michael Niedermayer
        st->codec->time_base= ap->time_base;
126 115329f1 Diego Biurrun
    } else if ( st->codec->codec_id == CODEC_ID_MJPEG ||
127 01f4895c Michael Niedermayer
                st->codec->codec_id == CODEC_ID_MPEG4 ||
128 17ac9f1c Luca Barbato
                st->codec->codec_id == CODEC_ID_DIRAC ||
129 0cd55b0c Michael Niedermayer
                st->codec->codec_id == CODEC_ID_DNXHD ||
130 1c169711 Michael Niedermayer
                st->codec->codec_id == CODEC_ID_VC1   ||
131 01f4895c Michael Niedermayer
                st->codec->codec_id == CODEC_ID_H264) {
132 4022fe01 Michael Niedermayer
        st->codec->time_base= (AVRational){1,25};
133 27e084bd Fabrice Bellard
    }
134 4022fe01 Michael Niedermayer
    av_set_pts_info(st, 64, 1, 1200000);
135 80ce3254 Michael Niedermayer
136 de6d9b64 Fabrice Bellard
    return 0;
137
}
138
139 900eb63d Diego Biurrun
/* Note: Do not forget to add new entries to the Makefile as well. */
140
141 9013560f Martin Storsjö
#if CONFIG_G722_DEMUXER
142 c6610a21 Diego Elio Pettenò
AVInputFormat ff_g722_demuxer = {
143 9013560f Martin Storsjö
    "g722",
144
    NULL_IF_CONFIG_SMALL("raw G.722"),
145
    0,
146
    NULL,
147
    ff_raw_read_header,
148
    ff_raw_read_partial_packet,
149
    .flags= AVFMT_GENERIC_INDEX,
150
    .extensions = "g722,722",
151
    .value = CODEC_ID_ADPCM_G722,
152
};
153
#endif
154
155 b250f9c6 Aurelien Jacobs
#if CONFIG_GSM_DEMUXER
156 c6610a21 Diego Elio Pettenò
AVInputFormat ff_gsm_demuxer = {
157 60711e95 Michael Niedermayer
    "gsm",
158 b4ee1d39 Diego Biurrun
    NULL_IF_CONFIG_SMALL("raw GSM"),
159 60711e95 Michael Niedermayer
    0,
160
    NULL,
161 6d0678d1 Aurelien Jacobs
    ff_raw_audio_read_header,
162 81f052cb Justin Ruggles
    ff_raw_read_partial_packet,
163 60711e95 Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
164
    .extensions = "gsm",
165
    .value = CODEC_ID_GSM,
166
};
167 7402ee23 Diego Biurrun
#endif
168 60711e95 Michael Niedermayer
169 b250f9c6 Aurelien Jacobs
#if CONFIG_MJPEG_DEMUXER
170 c6610a21 Diego Elio Pettenò
AVInputFormat ff_mjpeg_demuxer = {
171 76d32428 Diego Biurrun
    "mjpeg",
172 b4ee1d39 Diego Biurrun
    NULL_IF_CONFIG_SMALL("raw MJPEG video"),
173 0da71265 Michael Niedermayer
    0,
174 76d32428 Diego Biurrun
    NULL,
175 b47a5a95 Aurelien Jacobs
    ff_raw_video_read_header,
176 81f052cb Justin Ruggles
    ff_raw_read_partial_packet,
177 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
178 76d32428 Diego Biurrun
    .extensions = "mjpg,mjpeg",
179
    .value = CODEC_ID_MJPEG,
180 0da71265 Michael Niedermayer
};
181 7402ee23 Diego Biurrun
#endif
182 0da71265 Michael Niedermayer
183 b250f9c6 Aurelien Jacobs
#if CONFIG_MLP_DEMUXER
184 c6610a21 Diego Elio Pettenò
AVInputFormat ff_mlp_demuxer = {
185 76d32428 Diego Biurrun
    "mlp",
186
    NULL_IF_CONFIG_SMALL("raw MLP"),
187 c9a65ca8 Fabrice Bellard
    0,
188 76d32428 Diego Biurrun
    NULL,
189 6d0678d1 Aurelien Jacobs
    ff_raw_audio_read_header,
190 81f052cb Justin Ruggles
    ff_raw_read_partial_packet,
191 e9b78eeb Michael Niedermayer
    .flags= AVFMT_GENERIC_INDEX,
192 76d32428 Diego Biurrun
    .extensions = "mlp",
193
    .value = CODEC_ID_MLP,
194 de6d9b64 Fabrice Bellard
};
195 7402ee23 Diego Biurrun
#endif
196 de6d9b64 Fabrice Bellard
197 23d9cc45 Ramiro Polla
#if CONFIG_TRUEHD_DEMUXER
198 c6610a21 Diego Elio Pettenò
AVInputFormat ff_truehd_demuxer = {
199 23d9cc45 Ramiro Polla
    "truehd",
200
    NULL_IF_CONFIG_SMALL("raw TrueHD"),
201
    0,
202
    NULL,
203 6d0678d1 Aurelien Jacobs
    ff_raw_audio_read_header,
204 23d9cc45 Ramiro Polla
    ff_raw_read_partial_packet,
205
    .flags= AVFMT_GENERIC_INDEX,
206
    .extensions = "thd",
207
    .value = CODEC_ID_TRUEHD,
208
};
209
#endif
210
211 b250f9c6 Aurelien Jacobs
#if CONFIG_SHORTEN_DEMUXER
212 c6610a21 Diego Elio Pettenò
AVInputFormat ff_shorten_demuxer = {
213 76d32428 Diego Biurrun
    "shn",
214
    NULL_IF_CONFIG_SMALL("raw Shorten"),
215
    0,
216
    NULL,
217 6d0678d1 Aurelien Jacobs
    ff_raw_audio_read_header,
218 81f052cb Justin Ruggles
    ff_raw_read_partial_packet,
219 76d32428 Diego Biurrun
    .flags= AVFMT_GENERIC_INDEX,
220
    .extensions = "shn",
221
    .value = CODEC_ID_SHORTEN,
222
};
223 7402ee23 Diego Biurrun
#endif
224 76d32428 Diego Biurrun
225 b250f9c6 Aurelien Jacobs
#if CONFIG_VC1_DEMUXER
226 c6610a21 Diego Elio Pettenò
AVInputFormat ff_vc1_demuxer = {
227 7bb5c2a6 Kostya Shishkov
    "vc1",
228 bde15e74 Stefano Sabatini
    NULL_IF_CONFIG_SMALL("raw VC-1"),
229 7bb5c2a6 Kostya Shishkov
    0,
230
    NULL /* vc1_probe */,
231 b47a5a95 Aurelien Jacobs
    ff_raw_video_read_header,
232 81f052cb Justin Ruggles
    ff_raw_read_partial_packet,
233 7bb5c2a6 Kostya Shishkov
    .extensions = "vc1",
234
    .value = CODEC_ID_VC1,
235
};
236 7402ee23 Diego Biurrun
#endif