2 #include "libavcodec/get_bits.h"
3 #include "libavcodec/put_bits.h"
5 #define MAX_FRAME_SIZE 10
7 #define SYNC_WORD 0x6b21
11 static int probe(AVProbeData *p)
15 for(i=0; i+3<p->buf_size && i< 10*0x50; ){
16 if(AV_RL16(&p->buf[0]) != SYNC_WORD)
18 j=AV_RL16(&p->buf[2]);
19 if(j!=0x40 && j!=0x50)
23 return AVPROBE_SCORE_MAX/2;
26 static int read_header(AVFormatContext *s, AVFormatParameters *ap)
29 ByteIOContext *pb = s->pb;
31 st=av_new_stream(s, 0);
33 return AVERROR(ENOMEM);
35 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
36 st->codec->codec_id=CODEC_ID_G729;
37 st->codec->sample_rate=8000;
38 st->codec->block_align = 16;
39 st->codec->channels=1;
41 av_set_pts_info(st, 64, 1, 100);
45 static int read_packet(AVFormatContext *s,
48 ByteIOContext *pb = s->pb;
50 uint16_t buf[8 * MAX_FRAME_SIZE + 2];
59 sync = get_le16(pb); // sync word
60 packet_size = get_le16(pb) / 8;
61 if(packet_size > MAX_FRAME_SIZE)
64 ret = get_buffer(pb, (uint8_t*)buf, (8 * packet_size) * sizeof(uint16_t));
67 if(ret != 8 * packet_size * sizeof(uint16_t))
70 av_new_packet(pkt, packet_size);
72 init_put_bits(&pbo, pkt->data, packet_size);
73 for(j=0; j < packet_size; j++)
75 put_bits(&pbo,1, AV_RL16(src++) == BIT_1 ? 1 : 0);
83 AVInputFormat ff_bit_demuxer = {
85 "G.729 BIT file format",
94 static int write_header(AVFormatContext *s)
96 AVCodecContext *enc = s->streams[0]->codec;
98 enc->codec_id = CODEC_ID_G729;
100 enc->bits_per_coded_sample = 16;
101 enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3;
106 static int write_packet(AVFormatContext *s, AVPacket *pkt)
108 ByteIOContext *pb = s->pb;
113 put_le16(pb, SYNC_WORD);
114 put_le16(pb, 8 * 10);
116 init_get_bits(&gb, pkt->data, 8*10);
117 for(i=0; i< 8 * 10; i++)
118 put_le16(pb, get_bits1(&gb) ? BIT_1 : BIT_0);
119 put_flush_packet(pb);
124 AVOutputFormat ff_bit_muxer = {
126 "G.729 BIT file format",