#include "avformat.h"Go to the source code of this file.
Functions | |
| static int | amr_probe (AVProbeData *p) |
| static int | amr_read_header (AVFormatContext *s, AVFormatParameters *ap) |
| static int | amr_read_packet (AVFormatContext *s, AVPacket *pkt) |
Variables | |
| static const char | AMR_header [] = "#!AMR\n" |
| static const char | AMRWB_header [] = "#!AMR-WB\n" |
| static int amr_probe | ( | AVProbeData * | p | ) | [static] |
Definition at line 65 of file amr.c.
References AMR_header, AVPROBE_SCORE_MAX, and AVProbeData::buf.
00066 { 00067 //Only check for "#!AMR" which could be amr-wb, amr-nb. 00068 //This will also trigger multichannel files: "#!AMR_MC1.0\n" and 00069 //"#!AMR-WB_MC1.0\n" (not supported) 00070 00071 if(memcmp(p->buf,AMR_header,5)==0) 00072 return AVPROBE_SCORE_MAX; 00073 else 00074 return 0; 00075 }
| static int amr_read_header | ( | AVFormatContext * | s, | |
| AVFormatParameters * | ap | |||
| ) | [static] |
Definition at line 78 of file amr.c.
References AMR_header, AMRWB_header, av_new_stream(), av_set_pts_info(), AVERROR, AVCodecContext::channels, AVStream::codec, AVCodecContext::codec_id, CODEC_ID_AMR_NB, CODEC_ID_AMR_WB, AVCodecContext::codec_tag, AVCodecContext::codec_type, CODEC_TYPE_AUDIO, get_buffer(), MKTAG, AVFormatContext::pb, and AVCodecContext::sample_rate.
00080 { 00081 ByteIOContext *pb = s->pb; 00082 AVStream *st; 00083 uint8_t header[9]; 00084 00085 get_buffer(pb, header, 6); 00086 00087 st = av_new_stream(s, 0); 00088 if (!st) 00089 { 00090 return AVERROR(ENOMEM); 00091 } 00092 if(memcmp(header,AMR_header,6)!=0) 00093 { 00094 get_buffer(pb, header+6, 3); 00095 if(memcmp(header,AMRWB_header,9)!=0) 00096 { 00097 return -1; 00098 } 00099 00100 st->codec->codec_tag = MKTAG('s', 'a', 'w', 'b'); 00101 st->codec->codec_id = CODEC_ID_AMR_WB; 00102 st->codec->sample_rate = 16000; 00103 } 00104 else 00105 { 00106 st->codec->codec_tag = MKTAG('s', 'a', 'm', 'r'); 00107 st->codec->codec_id = CODEC_ID_AMR_NB; 00108 st->codec->sample_rate = 8000; 00109 } 00110 st->codec->channels = 1; 00111 st->codec->codec_type = CODEC_TYPE_AUDIO; 00112 av_set_pts_info(st, 64, 1, st->codec->sample_rate); 00113 00114 return 0; 00115 }
| static int amr_read_packet | ( | AVFormatContext * | s, | |
| AVPacket * | pkt | |||
| ) | [static] |
Definition at line 117 of file amr.c.
References av_free_packet(), av_new_packet(), AVERROR, AVStream::codec, AVCodecContext::codec_id, CODEC_ID_AMR_NB, CODEC_ID_AMR_WB, AVPacket::data, AVPacket::duration, get_buffer(), get_byte(), AVFormatContext::pb, AVPacket::pos, size, AVPacket::stream_index, AVFormatContext::streams, url_feof(), and url_ftell().
00119 { 00120 AVCodecContext *enc = s->streams[0]->codec; 00121 int read, size = 0, toc, mode; 00122 00123 if (url_feof(s->pb)) 00124 { 00125 return AVERROR(EIO); 00126 } 00127 00128 //FIXME this is wrong, this should rather be in a AVParset 00129 toc=get_byte(s->pb); 00130 mode = (toc >> 3) & 0x0F; 00131 00132 if (enc->codec_id == CODEC_ID_AMR_NB) 00133 { 00134 static const uint8_t packed_size[16] = {12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0}; 00135 00136 size=packed_size[mode]+1; 00137 } 00138 else if(enc->codec_id == CODEC_ID_AMR_WB) 00139 { 00140 static uint8_t packed_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1}; 00141 00142 size=packed_size[mode]; 00143 } 00144 else 00145 { 00146 assert(0); 00147 } 00148 00149 if ( (size==0) || av_new_packet(pkt, size)) 00150 { 00151 return AVERROR(EIO); 00152 } 00153 00154 pkt->stream_index = 0; 00155 pkt->pos= url_ftell(s->pb); 00156 pkt->data[0]=toc; 00157 pkt->duration= enc->codec_id == CODEC_ID_AMR_NB ? 160 : 320; 00158 read = get_buffer(s->pb, pkt->data+1, size-1); 00159 00160 if (read != size-1) 00161 { 00162 av_free_packet(pkt); 00163 return AVERROR(EIO); 00164 } 00165 00166 return 0; 00167 }
const char AMR_header[] = "#!AMR\n" [static] |
const char AMRWB_header[] = "#!AMR-WB\n" [static] |
1.5.1