• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

libavformat/rawdec.c

Go to the documentation of this file.
00001 /*
00002  * RAW demuxers
00003  * Copyright (c) 2001 Fabrice Bellard
00004  * Copyright (c) 2005 Alex Beregszaszi
00005  *
00006  * This file is part of Libav.
00007  *
00008  * Libav is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU Lesser General Public
00010  * License as published by the Free Software Foundation; either
00011  * version 2.1 of the License, or (at your option) any later version.
00012  *
00013  * Libav is distributed in the hope that it will be useful,
00014  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with Libav; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00021  */
00022 
00023 #include "avformat.h"
00024 #include "internal.h"
00025 #include "avio_internal.h"
00026 #include "rawdec.h"
00027 #include "libavutil/opt.h"
00028 #include "libavutil/parseutils.h"
00029 #include "libavutil/pixdesc.h"
00030 
00031 /* raw input */
00032 int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap)
00033 {
00034     AVStream *st;
00035     enum CodecID id;
00036 
00037     st = avformat_new_stream(s, NULL);
00038     if (!st)
00039         return AVERROR(ENOMEM);
00040 
00041         id = s->iformat->value;
00042         if (id == CODEC_ID_RAWVIDEO) {
00043             st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00044         } else {
00045             st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00046         }
00047         st->codec->codec_id = id;
00048 
00049         switch(st->codec->codec_type) {
00050         case AVMEDIA_TYPE_AUDIO: {
00051             RawAudioDemuxerContext *s1 = s->priv_data;
00052 
00053             st->codec->channels = 1;
00054 
00055             if (id == CODEC_ID_ADPCM_G722)
00056                 st->codec->sample_rate = 16000;
00057 
00058             if (s1 && s1->sample_rate)
00059                 st->codec->sample_rate = s1->sample_rate;
00060             if (s1 && s1->channels)
00061                 st->codec->channels    = s1->channels;
00062 
00063             st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id);
00064             assert(st->codec->bits_per_coded_sample > 0);
00065             st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8;
00066             avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
00067             break;
00068             }
00069         case AVMEDIA_TYPE_VIDEO: {
00070             FFRawVideoDemuxerContext *s1 = s->priv_data;
00071             int width = 0, height = 0, ret = 0;
00072             enum PixelFormat pix_fmt;
00073             AVRational framerate;
00074 
00075             if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) {
00076                 av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n");
00077                 goto fail;
00078             }
00079             if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == PIX_FMT_NONE) {
00080                 av_log(s, AV_LOG_ERROR, "No such pixel format: %s.\n", s1->pixel_format);
00081                 ret = AVERROR(EINVAL);
00082                 goto fail;
00083             }
00084             if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
00085                 av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
00086                 goto fail;
00087             }
00088             avpriv_set_pts_info(st, 64, framerate.den, framerate.num);
00089             st->codec->width  = width;
00090             st->codec->height = height;
00091             st->codec->pix_fmt = pix_fmt;
00092 fail:
00093             return ret;
00094             }
00095         default:
00096             return -1;
00097         }
00098     return 0;
00099 }
00100 
00101 #define RAW_PACKET_SIZE 1024
00102 
00103 int ff_raw_read_partial_packet(AVFormatContext *s, AVPacket *pkt)
00104 {
00105     int ret, size;
00106 
00107     size = RAW_PACKET_SIZE;
00108 
00109     if (av_new_packet(pkt, size) < 0)
00110         return AVERROR(ENOMEM);
00111 
00112     pkt->pos= avio_tell(s->pb);
00113     pkt->stream_index = 0;
00114     ret = ffio_read_partial(s->pb, pkt->data, size);
00115     if (ret < 0) {
00116         av_free_packet(pkt);
00117         return ret;
00118     }
00119     pkt->size = ret;
00120     return ret;
00121 }
00122 
00123 int ff_raw_audio_read_header(AVFormatContext *s,
00124                              AVFormatParameters *ap)
00125 {
00126     AVStream *st = avformat_new_stream(s, NULL);
00127     if (!st)
00128         return AVERROR(ENOMEM);
00129     st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00130     st->codec->codec_id = s->iformat->value;
00131     st->need_parsing = AVSTREAM_PARSE_FULL;
00132     st->start_time = 0;
00133     /* the parameters will be extracted from the compressed bitstream */
00134 
00135     return 0;
00136 }
00137 
00138 /* MPEG-1/H.263 input */
00139 int ff_raw_video_read_header(AVFormatContext *s,
00140                              AVFormatParameters *ap)
00141 {
00142     AVStream *st;
00143     FFRawVideoDemuxerContext *s1 = s->priv_data;
00144     AVRational framerate;
00145     int ret = 0;
00146 
00147 
00148     st = avformat_new_stream(s, NULL);
00149     if (!st) {
00150         ret = AVERROR(ENOMEM);
00151         goto fail;
00152     }
00153 
00154     st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00155     st->codec->codec_id = s->iformat->value;
00156     st->need_parsing = AVSTREAM_PARSE_FULL;
00157 
00158     if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) {
00159         av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate);
00160         goto fail;
00161     }
00162 
00163     st->r_frame_rate = st->avg_frame_rate = framerate;
00164     avpriv_set_pts_info(st, 64, 1, 1200000);
00165 
00166 fail:
00167     return ret;
00168 }
00169 
00170 /* Note: Do not forget to add new entries to the Makefile as well. */
00171 
00172 #define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x)
00173 #define DEC AV_OPT_FLAG_DECODING_PARAM
00174 const AVOption ff_rawvideo_options[] = {
00175     { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC},
00176     { NULL },
00177 };
00178 
00179 #if CONFIG_G722_DEMUXER
00180 AVInputFormat ff_g722_demuxer = {
00181     .name           = "g722",
00182     .long_name      = NULL_IF_CONFIG_SMALL("raw G.722"),
00183     .read_header    = ff_raw_read_header,
00184     .read_packet    = ff_raw_read_partial_packet,
00185     .flags= AVFMT_GENERIC_INDEX,
00186     .extensions = "g722,722",
00187     .value = CODEC_ID_ADPCM_G722,
00188 };
00189 #endif
00190 
00191 #if CONFIG_LATM_DEMUXER
00192 AVInputFormat ff_latm_demuxer = {
00193     .name           = "latm",
00194     .long_name      = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"),
00195     .read_header    = ff_raw_audio_read_header,
00196     .read_packet    = ff_raw_read_partial_packet,
00197     .flags= AVFMT_GENERIC_INDEX,
00198     .extensions = "latm",
00199     .value = CODEC_ID_AAC_LATM,
00200 };
00201 #endif
00202 
00203 #if CONFIG_MJPEG_DEMUXER
00204 FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg", CODEC_ID_MJPEG)
00205 #endif
00206 
00207 #if CONFIG_MLP_DEMUXER
00208 AVInputFormat ff_mlp_demuxer = {
00209     .name           = "mlp",
00210     .long_name      = NULL_IF_CONFIG_SMALL("raw MLP"),
00211     .read_header    = ff_raw_audio_read_header,
00212     .read_packet    = ff_raw_read_partial_packet,
00213     .flags= AVFMT_GENERIC_INDEX,
00214     .extensions = "mlp",
00215     .value = CODEC_ID_MLP,
00216 };
00217 #endif
00218 
00219 #if CONFIG_TRUEHD_DEMUXER
00220 AVInputFormat ff_truehd_demuxer = {
00221     .name           = "truehd",
00222     .long_name      = NULL_IF_CONFIG_SMALL("raw TrueHD"),
00223     .read_header    = ff_raw_audio_read_header,
00224     .read_packet    = ff_raw_read_partial_packet,
00225     .flags= AVFMT_GENERIC_INDEX,
00226     .extensions = "thd",
00227     .value = CODEC_ID_TRUEHD,
00228 };
00229 #endif
00230 
00231 #if CONFIG_SHORTEN_DEMUXER
00232 AVInputFormat ff_shorten_demuxer = {
00233     .name           = "shn",
00234     .long_name      = NULL_IF_CONFIG_SMALL("raw Shorten"),
00235     .read_header    = ff_raw_audio_read_header,
00236     .read_packet    = ff_raw_read_partial_packet,
00237     .flags          = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK,
00238     .extensions = "shn",
00239     .value = CODEC_ID_SHORTEN,
00240 };
00241 #endif
00242 
00243 #if CONFIG_VC1_DEMUXER
00244 FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", CODEC_ID_VC1)
00245 #endif
Generated on Thu Jul 11 2013 15:38:21 for Libav by doxygen 1.7.1