~ubuntu-branches/ubuntu/jaunty/xvidcap/jaunty-proposed

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/rtp_aac.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc, Andrew Starr-Bochicchio, Lionel Le Folgoc
  • Date: 2008-12-26 00:10:06 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20081226001006-2040ls9680bd1blt
Tags: 1.1.7-0.2ubuntu1
[ Andrew Starr-Bochicchio ]
* Merge from debian-multimedia (LP: #298547), Ubuntu Changes:
 - For ffmpeg-related build-deps, fix versionized dependencies
   as the ubuntu versioning is different than debian-multimedia's.

[ Lionel Le Folgoc ]
* LP: #311412 is fixed since the 1.1.7~rc1-0.1 revision.
* debian/patches/03_ffmpeg.diff: updated to fix FTBFS due to libswscale API
  change (cherry-pick from Gentoo #234383).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * copyright (c) 2007 Luca Abeni
 
3
 *
 
4
 * This file is part of FFmpeg.
 
5
 *
 
6
 * FFmpeg 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.1 of the License, or (at your option) any later version.
 
10
 *
 
11
 * FFmpeg 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 FFmpeg; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
19
 */
 
20
 
 
21
#include "avformat.h"
 
22
#include "rtp_aac.h"
 
23
#include "rtp_internal.h"
 
24
 
 
25
#define MAX_FRAMES_PER_PACKET (s->max_frames_per_packet ? s->max_frames_per_packet : 5)
 
26
#define MAX_AU_HEADERS_SIZE (2 + 2 * MAX_FRAMES_PER_PACKET)
 
27
 
 
28
void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size)
 
29
{
 
30
    RTPDemuxContext *s = s1->priv_data;
 
31
    int len, max_packet_size;
 
32
    uint8_t *p;
 
33
 
 
34
    /* skip ADTS header, if present */
 
35
    if ((s1->streams[0]->codec->extradata_size) == 0) {
 
36
        size -= 7;
 
37
        buff += 7;
 
38
    }
 
39
    max_packet_size = s->max_payload_size - MAX_AU_HEADERS_SIZE;
 
40
 
 
41
    /* test if the packet must be sent */
 
42
    len = (s->buf_ptr - s->buf);
 
43
    if ((s->read_buf_index == MAX_FRAMES_PER_PACKET) || (len && (len + size) > max_packet_size)) {
 
44
        int au_size = s->read_buf_index * 2;
 
45
 
 
46
        p = s->buf + MAX_AU_HEADERS_SIZE - au_size - 2;
 
47
        if (p != s->buf) {
 
48
            memmove(p + 2, s->buf + 2, au_size);
 
49
        }
 
50
        /* Write the AU header size */
 
51
        p[0] = ((au_size * 8) & 0xFF) >> 8;
 
52
        p[1] = (au_size * 8) & 0xFF;
 
53
 
 
54
        ff_rtp_send_data(s1, p, s->buf_ptr - p, 1);
 
55
 
 
56
        s->read_buf_index = 0;
 
57
    }
 
58
    if (s->read_buf_index == 0) {
 
59
        s->buf_ptr = s->buf + MAX_AU_HEADERS_SIZE;
 
60
        s->timestamp = s->cur_timestamp;
 
61
    }
 
62
 
 
63
    if (size < max_packet_size) {
 
64
        p = s->buf + s->read_buf_index++ * 2 + 2;
 
65
        *p++ = size >> 5;
 
66
        *p = (size & 0x1F) << 3;
 
67
        memcpy(s->buf_ptr, buff, size);
 
68
        s->buf_ptr += size;
 
69
    } else {
 
70
        if (s->buf_ptr != s->buf + MAX_AU_HEADERS_SIZE) {
 
71
            av_log(s1, AV_LOG_ERROR, "Strange...\n");
 
72
            av_abort();
 
73
        }
 
74
        max_packet_size = s->max_payload_size - 4;
 
75
        p = s->buf;
 
76
        p[0] = 0;
 
77
        p[1] = 16;
 
78
        while (size > 0) {
 
79
            len = FFMIN(size, max_packet_size);
 
80
            p[2] = len >> 5;
 
81
            p[3] = (size & 0x1F) << 3;
 
82
            memcpy(p + 4, buff, len);
 
83
            ff_rtp_send_data(s1, p, len + 4, len == size);
 
84
            size -= len;
 
85
            buff += len;
 
86
        }
 
87
    }
 
88
}