~ubuntu-branches/ubuntu/oneiric/libav/oneiric

« back to all changes in this revision

Viewing changes to libavformat/soxenc.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-30 14:27:42 UTC
  • mfrom: (1.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430142742-quvblxk1tj6adlh5
Tags: 4:0.7~b1-1ubuntu1
* Merge from debian. Remaining changes:
  - don't build against libfaad, libdirac, librtmp and libopenjpeg
    (all in universe)
  - explicitly --enable-pic on powerpc, cf. LP #654666
  - different arm configure bits that should probably better be
    merged into debian
* Cherry-picked from git: 
  - install doc/APIChanges and refer to them in NEWS.Debian (Closes: #623682)
  - don't try to install non-existing documentation, fixes FTBFS on powerpc

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 * Based on libSoX sox-fmt.c
6
6
 * Copyright (c) 2008 robs@users.sourceforge.net
7
7
 *
8
 
 * This file is part of FFmpeg.
 
8
 * This file is part of Libav.
9
9
 *
10
 
 * FFmpeg is free software; you can redistribute it and/or
 
10
 * Libav is free software; you can redistribute it and/or
11
11
 * modify it under the terms of the GNU Lesser General Public
12
12
 * License as published by the Free Software Foundation; either
13
13
 * version 2.1 of the License, or (at your option) any later version.
14
14
 *
15
 
 * FFmpeg is distributed in the hope that it will be useful,
 
15
 * Libav is distributed in the hope that it will be useful,
16
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
18
 * Lesser General Public License for more details.
19
19
 *
20
20
 * You should have received a copy of the GNU Lesser General Public
21
 
 * License along with FFmpeg; if not, write to the Free Software
 
21
 * License along with Libav; if not, write to the Free Software
22
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
23
 */
24
24
 
31
31
 
32
32
#include "libavutil/intreadwrite.h"
33
33
#include "avformat.h"
 
34
#include "avio_internal.h"
34
35
#include "sox.h"
35
36
 
36
37
typedef struct {
40
41
static int sox_write_header(AVFormatContext *s)
41
42
{
42
43
    SoXContext *sox = s->priv_data;
43
 
    ByteIOContext *pb = s->pb;
 
44
    AVIOContext *pb = s->pb;
44
45
    AVCodecContext *enc = s->streams[0]->codec;
45
46
    AVMetadataTag *comment;
46
47
    size_t comment_len = 0, comment_size;
53
54
    sox->header_size = SOX_FIXED_HDR + comment_size;
54
55
 
55
56
    if (enc->codec_id == CODEC_ID_PCM_S32LE) {
56
 
        put_tag(pb, ".SoX");
57
 
        put_le32(pb, sox->header_size);
58
 
        put_le64(pb, 0); /* number of samples */
59
 
        put_le64(pb, av_dbl2int(enc->sample_rate));
60
 
        put_le32(pb, enc->channels);
61
 
        put_le32(pb, comment_size);
 
57
        ffio_wfourcc(pb, ".SoX");
 
58
        avio_wl32(pb, sox->header_size);
 
59
        avio_wl64(pb, 0); /* number of samples */
 
60
        avio_wl64(pb, av_dbl2int(enc->sample_rate));
 
61
        avio_wl32(pb, enc->channels);
 
62
        avio_wl32(pb, comment_size);
62
63
    } else if (enc->codec_id == CODEC_ID_PCM_S32BE) {
63
 
        put_tag(pb, "XoS.");
64
 
        put_be32(pb, sox->header_size);
65
 
        put_be64(pb, 0); /* number of samples */
66
 
        put_be64(pb, av_dbl2int(enc->sample_rate));
67
 
        put_be32(pb, enc->channels);
68
 
        put_be32(pb, comment_size);
 
64
        ffio_wfourcc(pb, "XoS.");
 
65
        avio_wb32(pb, sox->header_size);
 
66
        avio_wb64(pb, 0); /* number of samples */
 
67
        avio_wb64(pb, av_dbl2int(enc->sample_rate));
 
68
        avio_wb32(pb, enc->channels);
 
69
        avio_wb32(pb, comment_size);
69
70
    } else {
70
71
        av_log(s, AV_LOG_ERROR, "invalid codec; use pcm_s32le or pcm_s32be\n");
71
72
        return -1;
72
73
    }
73
74
 
74
75
    if (comment_len)
75
 
        put_buffer(pb, comment->value, comment_len);
 
76
        avio_write(pb, comment->value, comment_len);
76
77
 
77
78
    for ( ; comment_size > comment_len; comment_len++)
78
 
        put_byte(pb, 0);
 
79
        avio_w8(pb, 0);
79
80
 
80
 
    put_flush_packet(pb);
 
81
    avio_flush(pb);
81
82
 
82
83
    return 0;
83
84
}
84
85
 
85
86
static int sox_write_packet(AVFormatContext *s, AVPacket *pkt)
86
87
{
87
 
    ByteIOContext *pb = s->pb;
88
 
    put_buffer(pb, pkt->data, pkt->size);
 
88
    AVIOContext *pb = s->pb;
 
89
    avio_write(pb, pkt->data, pkt->size);
89
90
    return 0;
90
91
}
91
92
 
92
93
static int sox_write_trailer(AVFormatContext *s)
93
94
{
94
95
    SoXContext *sox = s->priv_data;
95
 
    ByteIOContext *pb = s->pb;
 
96
    AVIOContext *pb = s->pb;
96
97
    AVCodecContext *enc = s->streams[0]->codec;
97
98
 
98
 
    if (!url_is_streamed(s->pb)) {
 
99
    if (s->pb->seekable) {
99
100
        /* update number of samples */
100
 
        int64_t file_size = url_ftell(pb);
 
101
        int64_t file_size = avio_tell(pb);
101
102
        int64_t num_samples = (file_size - sox->header_size - 4LL) >> 2LL;
102
 
        url_fseek(pb, 8, SEEK_SET);
 
103
        avio_seek(pb, 8, SEEK_SET);
103
104
        if (enc->codec_id == CODEC_ID_PCM_S32LE) {
104
 
            put_le64(pb, num_samples);
 
105
            avio_wl64(pb, num_samples);
105
106
        } else
106
 
            put_be64(pb, num_samples);
107
 
        url_fseek(pb, file_size, SEEK_SET);
 
107
            avio_wb64(pb, num_samples);
 
108
        avio_seek(pb, file_size, SEEK_SET);
108
109
 
109
 
        put_flush_packet(pb);
 
110
        avio_flush(pb);
110
111
    }
111
112
 
112
113
    return 0;
113
114
}
114
115
 
115
 
AVOutputFormat sox_muxer = {
 
116
AVOutputFormat ff_sox_muxer = {
116
117
    "sox",
117
118
    NULL_IF_CONFIG_SMALL("SoX native format"),
118
119
    NULL,