Revision a283db39

View differences:

libavformat/Makefile
27 27

  
28 28
# muxers
29 29
ifeq ($(CONFIG_MUXERS),yes)
30
OBJS+= flvenc.o movenc.o asf-enc.o
30
OBJS+= flvenc.o movenc.o asf-enc.o adtsenc.o
31 31
endif
32 32

  
33 33

  
libavformat/adtsenc.c
1
/*
2
 * ADTS muxer.
3
 * Copyright (c) 2006 Baptiste Coudurier <baptiste.coudurier@smartjog.com>
4
 *                    Mans Rullgard <mru@inprovide.com>
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 2 of the License, or (at your option) any later version.
10
 *
11
 * This library is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
 */
20
#include "avformat.h"
21
#include "bitstream.h"
22

  
23
#define ADTS_HEADER_SIZE 7
24

  
25
typedef struct {
26
    int write_adts;
27
    int objecttype;
28
    int sample_rate_index;
29
    int channel_conf;
30
} ADTSContext;
31

  
32
static int decode_extradata(ADTSContext *adts, uint8_t *buf, int size)
33
{
34
    GetBitContext gb;
35

  
36
    init_get_bits(&gb, buf, size * 8);
37
    adts->objecttype = get_bits(&gb, 5) - 1;
38
    adts->sample_rate_index = get_bits(&gb, 4);
39
    adts->channel_conf = get_bits(&gb, 4);
40

  
41
    adts->write_adts = 1;
42

  
43
    return 0;
44
}
45

  
46
static int adts_write_header(AVFormatContext *s)
47
{
48
    ADTSContext *adts = s->priv_data;
49
    AVCodecContext *avc = s->streams[0]->codec;
50

  
51
    if(avc->extradata_size > 0)
52
        decode_extradata(adts, avc->extradata, avc->extradata_size);
53

  
54
    return 0;
55
}
56

  
57
static int adts_write_frame_header(AVFormatContext *s, int size)
58
{
59
    ADTSContext *ctx = s->priv_data;
60
    PutBitContext pb;
61
    uint8_t buf[ADTS_HEADER_SIZE];
62

  
63
    init_put_bits(&pb, buf, ADTS_HEADER_SIZE);
64

  
65
    /* adts_fixed_header */
66
    put_bits(&pb, 12, 0xfff);   /* syncword */
67
    put_bits(&pb, 1, 0);        /* ID */
68
    put_bits(&pb, 2, 0);        /* layer */
69
    put_bits(&pb, 1, 1);        /* protection_absent */
70
    put_bits(&pb, 2, ctx->objecttype); /* profile_objecttype */
71
    put_bits(&pb, 4, ctx->sample_rate_index);
72
    put_bits(&pb, 1, 0);        /* private_bit */
73
    put_bits(&pb, 3, ctx->channel_conf); /* channel_configuration */
74
    put_bits(&pb, 1, 0);        /* original_copy */
75
    put_bits(&pb, 1, 0);        /* home */
76

  
77
    /* adts_variable_header */
78
    put_bits(&pb, 1, 0);        /* copyright_identification_bit */
79
    put_bits(&pb, 1, 0);        /* copyright_identification_start */
80
    put_bits(&pb, 13, ADTS_HEADER_SIZE + size); /* aac_frame_length */
81
    put_bits(&pb, 11, 0x7ff);   /* adts_buffer_fullness */
82
    put_bits(&pb, 2, 0);        /* number_of_raw_data_blocks_in_frame */
83

  
84
    flush_put_bits(&pb);
85
    put_buffer(&s->pb, buf, ADTS_HEADER_SIZE);
86

  
87
    return 0;
88
}
89

  
90
static int adts_write_trailer(AVFormatContext *s)
91
{
92
    return 0;
93
}
94

  
95
static int adts_write_packet(AVFormatContext *s, AVPacket *pkt)
96
{
97
    ADTSContext *adts = s->priv_data;
98
    ByteIOContext *pb = &s->pb;
99

  
100
    if(adts->write_adts)
101
        adts_write_frame_header(s, pkt->size);
102
    put_buffer(pb, pkt->data, pkt->size);
103

  
104
    return 0;
105
}
106

  
107
#ifdef CONFIG_MUXERS
108
static AVOutputFormat adts_oformat = {
109
    "adts",
110
    "ADTS AAC",
111
    "audio/aac",
112
    "aac",
113
    sizeof(ADTSContext),
114
    CODEC_ID_AAC,
115
    CODEC_ID_NONE,
116
    adts_write_header,
117
    adts_write_packet,
118
    adts_write_trailer,
119
};
120
#endif //CONFIG_MUXERS
121

  
122
int ff_adts_init(void)
123
{
124
#ifdef CONFIG_MUXERS
125
    av_register_output_format(&adts_oformat);
126
#endif //CONFIG_MUXERS
127
    return 0;
128
}
libavformat/allformats.c
55 55
    swf_init();
56 56
    au_init();
57 57
    ff_aiff_init();
58
    ff_adts_init();
58 59
#ifdef CONFIG_MUXERS
59 60
    gif_init();
60 61
#endif //CONFIG_MUXERS
libavformat/avformat.h
5 5
extern "C" {
6 6
#endif
7 7

  
8
#define LIBAVFORMAT_VERSION_INT ((50<<16)+(2<<8)+0)
9
#define LIBAVFORMAT_VERSION     50.2.0
8
#define LIBAVFORMAT_VERSION_INT ((50<<16)+(2<<8)+1)
9
#define LIBAVFORMAT_VERSION     50.2.1
10 10
#define LIBAVFORMAT_BUILD       LIBAVFORMAT_VERSION_INT
11 11

  
12 12
#define LIBAVFORMAT_IDENT       "Lavf" AV_STRINGIFY(LIBAVFORMAT_VERSION)
......
555 555
/* voc.c */
556 556
int voc_init(void);
557 557

  
558
/* adts.c */
559
int ff_adts_init(void);
560

  
558 561
#include "rtp.h"
559 562

  
560 563
#include "rtsp.h"
libavformat/raw.c
417 417
    .extensions = "aac",
418 418
};
419 419

  
420
#ifdef CONFIG_MUXERS
421
AVOutputFormat aac_oformat = {
422
    "aac",
423
    "ADTS AAC",
424
    "audio/aac",
425
    "aac",
426
    0,
427
    CODEC_ID_AAC,
428
    0,
429
    raw_write_header,
430
    raw_write_packet,
431
    raw_write_trailer,
432
};
433
#endif
434

  
435 420
AVInputFormat h261_iformat = {
436 421
    "h261",
437 422
    "raw h261",
......
783 768
    av_register_output_format(&ac3_oformat);
784 769

  
785 770
    av_register_input_format(&aac_iformat);
786
    av_register_output_format(&aac_oformat);
787 771

  
788 772
    av_register_input_format(&dts_iformat);
789 773

  

Also available in: Unified diff