~siretart/ubuntu/utopic/libav/libav10

« back to all changes in this revision

Viewing changes to libavcodec/dca_parser.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-05-11 12:28:45 UTC
  • mfrom: (1.1.22) (2.1.38 experimental)
  • Revision ID: package-import@ubuntu.com-20140511122845-gxvpts83i958y0i5
Tags: 6:10.1-1
* New upstream release 10:
   - pcm-dvd: Fix 20bit decoding (bug/592)
   - avi: Improve non-interleaved detection (bug/666)
   - arm: hpeldsp: fix put_pixels8_y2_{,no_rnd_}armv6
   - arm: hpeldsp: prevent overreads in armv6 asm (bug/646)
   - avfilter: Add missing emms_c when needed
   - rtmpproto: Check the buffer sizes when copying app/playpath strings
   - swscale: Fix an undefined behaviour
   - vp9: Read the frame size as unsigned
   - dcadec: Use correct channel count in stereo downmix check
   - dcadec: Do not decode the XCh extension when downmixing to stereo
   - matroska: add the Opus mapping
   - matroskadec: read the CodecDelay element
   - rtmpproto: Make sure to pass on the error code if read_connect failed
   - lavr: allocate the resampling buffer with a positive size
   - mp3enc: Properly write bitrate value in XING header (Closes: #736088)
   - golomb: Fix the implementation of get_se_golomb_long
* Drop debian/libav-tools.maintscript. ffserver is no longer found in
  stable, and this seems to cause other problems today (Closes: #742676)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "parser.h"
26
26
#include "dca.h"
27
 
#include "dca_parser.h"
28
27
#include "get_bits.h"
29
 
#include "put_bits.h"
30
28
 
31
29
typedef struct DCAParseContext {
32
30
    ParseContext pc;
62
60
            if (IS_MARKER(state, i, buf, buf_size)) {
63
61
                if (pc1->lastmarker && state == pc1->lastmarker) {
64
62
                    start_found = 1;
 
63
                    i++;
65
64
                    break;
66
65
                } else if (!pc1->lastmarker) {
67
66
                    start_found = 1;
68
67
                    pc1->lastmarker = state;
 
68
                    i++;
69
69
                    break;
70
70
                }
71
71
            }
80
80
            if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) {
81
81
                if(pc1->framesize > pc1->size)
82
82
                    continue;
83
 
                if(!pc1->framesize){
84
 
                    pc1->framesize = pc1->hd_pos ? pc1->hd_pos : pc1->size;
85
 
                }
86
83
                pc->frame_start_found = 0;
87
84
                pc->state = -1;
88
85
                pc1->size = 0;
103
100
    return 0;
104
101
}
105
102
 
106
 
int ff_dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst,
107
 
                             int max_size)
108
 
{
109
 
    uint32_t mrk;
110
 
    int i, tmp;
111
 
    const uint16_t *ssrc = (const uint16_t *) src;
112
 
    uint16_t *sdst = (uint16_t *) dst;
113
 
    PutBitContext pb;
114
 
 
115
 
    if ((unsigned) src_size > (unsigned) max_size)
116
 
        src_size = max_size;
117
 
 
118
 
    mrk = AV_RB32(src);
119
 
    switch (mrk) {
120
 
    case DCA_MARKER_RAW_BE:
121
 
        memcpy(dst, src, src_size);
122
 
        return src_size;
123
 
    case DCA_MARKER_RAW_LE:
124
 
        for (i = 0; i < (src_size + 1) >> 1; i++)
125
 
            *sdst++ = av_bswap16(*ssrc++);
126
 
        return src_size;
127
 
    case DCA_MARKER_14B_BE:
128
 
    case DCA_MARKER_14B_LE:
129
 
        init_put_bits(&pb, dst, max_size);
130
 
        for (i = 0; i < (src_size + 1) >> 1; i++, src += 2) {
131
 
            tmp = ((mrk == DCA_MARKER_14B_BE) ? AV_RB16(src) : AV_RL16(src)) & 0x3FFF;
132
 
            put_bits(&pb, 14, tmp);
133
 
        }
134
 
        flush_put_bits(&pb);
135
 
        return (put_bits_count(&pb) + 7) >> 3;
136
 
    default:
137
 
        return AVERROR_INVALIDDATA;
138
 
    }
139
 
}
140
 
 
141
103
static int dca_parse_params(const uint8_t *buf, int buf_size, int *duration,
142
 
                            int *sample_rate)
 
104
                            int *sample_rate, int *framesize)
143
105
{
144
106
    GetBitContext gb;
145
107
    uint8_t hdr[12 + FF_INPUT_BUFFER_PADDING_SIZE] = { 0 };
159
121
        return AVERROR_INVALIDDATA;
160
122
    *duration = 256 * (sample_blocks / 8);
161
123
 
162
 
    skip_bits(&gb, 20);
 
124
    *framesize = get_bits(&gb, 14) + 1;
 
125
    if (*framesize < 95)
 
126
        return AVERROR_INVALIDDATA;
 
127
 
 
128
    skip_bits(&gb, 6);
163
129
    sr_code = get_bits(&gb, 4);
164
130
    *sample_rate = avpriv_dca_sample_rates[sr_code];
165
131
    if (*sample_rate == 0)
190
156
    }
191
157
 
192
158
    /* read the duration and sample rate from the frame header */
193
 
    if (!dca_parse_params(buf, buf_size, &duration, &sample_rate)) {
 
159
    if (!dca_parse_params(buf, buf_size, &duration, &sample_rate, &pc1->framesize)) {
194
160
        s->duration = duration;
195
161
        avctx->sample_rate = sample_rate;
196
162
    } else