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

libavformat/pcmdec.c

Go to the documentation of this file.
00001 /*
00002  * RAW PCM demuxers
00003  * Copyright (c) 2002 Fabrice Bellard
00004  *
00005  * This file is part of Libav.
00006  *
00007  * Libav is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * Libav is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with Libav; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "avformat.h"
00023 #include "rawdec.h"
00024 #include "pcm.h"
00025 #include "libavutil/log.h"
00026 #include "libavutil/opt.h"
00027 
00028 #define RAW_SAMPLES     1024
00029 
00030 static int raw_read_packet(AVFormatContext *s, AVPacket *pkt)
00031 {
00032     int ret, size, bps;
00033     //    AVStream *st = s->streams[0];
00034 
00035     size= RAW_SAMPLES*s->streams[0]->codec->block_align;
00036 
00037     ret= av_get_packet(s->pb, pkt, size);
00038 
00039     pkt->stream_index = 0;
00040     if (ret < 0)
00041         return ret;
00042 
00043     bps= av_get_bits_per_sample(s->streams[0]->codec->codec_id);
00044     assert(bps); // if false there IS a bug elsewhere (NOT in this function)
00045     pkt->dts=
00046     pkt->pts= pkt->pos*8 / (bps * s->streams[0]->codec->channels);
00047 
00048     return ret;
00049 }
00050 
00051 static const AVOption pcm_options[] = {
00052     { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
00053     { "channels",    "", offsetof(RawAudioDemuxerContext, channels),    AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM },
00054     { NULL },
00055 };
00056 
00057 #define PCMDEF(name_, long_name_, ext, codec)               \
00058 static const AVClass name_ ## _demuxer_class = {            \
00059     .class_name = #name_ " demuxer",                        \
00060     .item_name  = av_default_item_name,                     \
00061     .option     = pcm_options,                              \
00062     .version    = LIBAVUTIL_VERSION_INT,                    \
00063 };                                                          \
00064 AVInputFormat ff_pcm_ ## name_ ## _demuxer = {              \
00065     .name           = #name_,                               \
00066     .long_name      = NULL_IF_CONFIG_SMALL(long_name_),     \
00067     .priv_data_size = sizeof(RawAudioDemuxerContext),       \
00068     .read_header    = ff_raw_read_header,                   \
00069     .read_packet    = raw_read_packet,                      \
00070     .read_seek      = pcm_read_seek,                        \
00071     .flags          = AVFMT_GENERIC_INDEX,                  \
00072     .extensions     = ext,                                  \
00073     .value          = codec,                                \
00074     .priv_class     = &name_ ## _demuxer_class,             \
00075 };
00076 
00077 PCMDEF(f64be, "PCM 64 bit floating-point big-endian format",
00078        NULL, CODEC_ID_PCM_F64BE)
00079 
00080 PCMDEF(f64le, "PCM 64 bit floating-point little-endian format",
00081        NULL, CODEC_ID_PCM_F64LE)
00082 
00083 PCMDEF(f32be, "PCM 32 bit floating-point big-endian format",
00084        NULL, CODEC_ID_PCM_F32BE)
00085 
00086 PCMDEF(f32le, "PCM 32 bit floating-point little-endian format",
00087        NULL, CODEC_ID_PCM_F32LE)
00088 
00089 PCMDEF(s32be, "PCM signed 32 bit big-endian format",
00090        NULL, CODEC_ID_PCM_S32BE)
00091 
00092 PCMDEF(s32le, "PCM signed 32 bit little-endian format",
00093        NULL, CODEC_ID_PCM_S32LE)
00094 
00095 PCMDEF(s24be, "PCM signed 24 bit big-endian format",
00096        NULL, CODEC_ID_PCM_S24BE)
00097 
00098 PCMDEF(s24le, "PCM signed 24 bit little-endian format",
00099        NULL, CODEC_ID_PCM_S24LE)
00100 
00101 PCMDEF(s16be, "PCM signed 16 bit big-endian format",
00102        AV_NE("sw", NULL), CODEC_ID_PCM_S16BE)
00103 
00104 PCMDEF(s16le, "PCM signed 16 bit little-endian format",
00105        AV_NE(NULL, "sw"), CODEC_ID_PCM_S16LE)
00106 
00107 PCMDEF(s8, "PCM signed 8 bit format",
00108        "sb", CODEC_ID_PCM_S8)
00109 
00110 PCMDEF(u32be, "PCM unsigned 32 bit big-endian format",
00111        NULL, CODEC_ID_PCM_U32BE)
00112 
00113 PCMDEF(u32le, "PCM unsigned 32 bit little-endian format",
00114        NULL, CODEC_ID_PCM_U32LE)
00115 
00116 PCMDEF(u24be, "PCM unsigned 24 bit big-endian format",
00117        NULL, CODEC_ID_PCM_U24BE)
00118 
00119 PCMDEF(u24le, "PCM unsigned 24 bit little-endian format",
00120        NULL, CODEC_ID_PCM_U24LE)
00121 
00122 PCMDEF(u16be, "PCM unsigned 16 bit big-endian format",
00123        AV_NE("uw", NULL), CODEC_ID_PCM_U16BE)
00124 
00125 PCMDEF(u16le, "PCM unsigned 16 bit little-endian format",
00126        AV_NE(NULL, "uw"), CODEC_ID_PCM_U16LE)
00127 
00128 PCMDEF(u8, "PCM unsigned 8 bit format",
00129        "ub", CODEC_ID_PCM_U8)
00130 
00131 PCMDEF(alaw, "PCM A-law format",
00132        "al", CODEC_ID_PCM_ALAW)
00133 
00134 PCMDEF(mulaw, "PCM mu-law format",
00135        "ul", CODEC_ID_PCM_MULAW)
Generated on Sat Mar 17 2012 12:57:54 for Libav by doxygen 1.7.1