~ubuntu-branches/ubuntu/quantal/gst-plugins-bad-multiverse0.10/quantal

« back to all changes in this revision

Viewing changes to gst/mpegpsmux/mpegpsmux_aac.c

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-12-07 08:54:28 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20091207085428-ml6aaukf0p2ph34d
Tags: 0.10.17-0ubuntu1
* New upstream release.
* Add myself to maintainer.
* Fix misc lintian warnings.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright 2006, 2007, 2008 Fluendo S.A. 
 
3
 *  Authors: Jan Schmidt <jan@fluendo.com>
 
4
 *           Kapil Agrawal <kapil@fluendo.com>
 
5
 *           Julien Moutte <julien@fluendo.com>
 
6
 *
 
7
 * Copyright 2008 Lin YANG <oxcsnicho@gmail.com>
 
8
 *
 
9
 * This library is licensed under 4 different licenses and you
 
10
 * can choose to use it under the terms of any one of them. The
 
11
 * four licenses are the MPL 1.1, the LGPL, the GPL and the MIT
 
12
 * license.
 
13
 *
 
14
 * MPL:
 
15
 * 
 
16
 * The contents of this file are subject to the Mozilla Public License
 
17
 * Version 1.1 (the "License"); you may not use this file except in
 
18
 * compliance with the License. You may obtain a copy of the License at
 
19
 * http://www.mozilla.org/MPL/.
 
20
 *
 
21
 * Software distributed under the License is distributed on an "AS IS"
 
22
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 
23
 * License for the specific language governing rights and limitations
 
24
 * under the License.
 
25
 *
 
26
 * LGPL:
 
27
 *
 
28
 * This library is free software; you can redistribute it and/or
 
29
 * modify it under the terms of the GNU Library General Public
 
30
 * License as published by the Free Software Foundation; either
 
31
 * version 2 of the License, or (at your option) any later version.
 
32
 *
 
33
 * This library is distributed in the hope that it will be useful,
 
34
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
35
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
36
 * Library General Public License for more details.
 
37
 *
 
38
 * You should have received a copy of the GNU Library General Public
 
39
 * License along with this library; if not, write to the
 
40
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
41
 * Boston, MA 02111-1307, USA.
 
42
 *
 
43
 * GPL:
 
44
 *
 
45
 * This program is free software; you can redistribute it and/or modify
 
46
 * it under the terms of the GNU General Public License as published by
 
47
 * the Free Software Foundation; either version 2 of the License, or
 
48
 * (at your option) any later version.
 
49
 *
 
50
 * This program is distributed in the hope that it will be useful,
 
51
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
52
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
53
 * GNU General Public License for more details.
 
54
 *
 
55
 * You should have received a copy of the GNU General Public License
 
56
 * along with this program; if not, write to the Free Software
 
57
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
58
 *
 
59
 * MIT:
 
60
 *
 
61
 * Unless otherwise indicated, Source Code is licensed under MIT license.
 
62
 * See further explanation attached in License Statement (distributed in the file
 
63
 * LICENSE).
 
64
 * 
 
65
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 
66
 * this software and associated documentation files (the "Software"), to deal in
 
67
 * the Software without restriction, including without limitation the rights to
 
68
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 
69
 * of the Software, and to permit persons to whom the Software is furnished to do
 
70
 * so, subject to the following conditions:
 
71
 * 
 
72
 * The above copyright notice and this permission notice shall be included in all
 
73
 * copies or substantial portions of the Software.
 
74
 * 
 
75
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
76
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
77
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
78
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
79
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
80
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
81
 * SOFTWARE.
 
82
 *
 
83
 */
 
84
 
 
85
#ifdef HAVE_CONFIG_H
 
86
#include "config.h"
 
87
#endif
 
88
 
 
89
#include "mpegpsmux_aac.h"
 
90
#include <string.h>
 
91
 
 
92
GST_DEBUG_CATEGORY_EXTERN (mpegpsmux_debug);
 
93
#define GST_CAT_DEFAULT mpegpsmux_debug
 
94
 
 
95
GstBuffer *
 
96
mpegpsmux_prepare_aac (GstBuffer * buf, MpegPsPadData * data, MpegPsMux * mux)
 
97
{
 
98
  guint8 adts_header[7] = { 0, };
 
99
  GstBuffer *out_buf = gst_buffer_new_and_alloc (GST_BUFFER_SIZE (buf) + 7);
 
100
  gsize out_offset = 0;
 
101
  guint8 rate_idx = 0, channels = 0, obj_type = 0;
 
102
 
 
103
  GST_DEBUG_OBJECT (mux, "Preparing AAC buffer for output");
 
104
 
 
105
  /* We want the same metadata */
 
106
  gst_buffer_copy_metadata (out_buf, buf, GST_BUFFER_COPY_ALL);
 
107
 
 
108
  /* Generate ADTS header */
 
109
  obj_type = (GST_READ_UINT8 (GST_BUFFER_DATA (data->codec_data)) & 0xC) >> 2;
 
110
  obj_type++;
 
111
  rate_idx = (GST_READ_UINT8 (GST_BUFFER_DATA (data->codec_data)) & 0x3) << 1;
 
112
  rate_idx |=
 
113
      (GST_READ_UINT8 (GST_BUFFER_DATA (data->codec_data) + 1) & 0x80) >> 7;
 
114
  channels =
 
115
      (GST_READ_UINT8 (GST_BUFFER_DATA (data->codec_data) + 1) & 0x78) >> 3;
 
116
  GST_DEBUG_OBJECT (mux, "Rate index %u, channels %u, object type %u", rate_idx,
 
117
      channels, obj_type);
 
118
  /* Sync point over a full byte */
 
119
  adts_header[0] = 0xFF;
 
120
  /* Sync point continued over first 4 bits + static 4 bits
 
121
   * (ID, layer, protection)*/
 
122
  adts_header[1] = 0xF1;
 
123
  /* Object type over first 2 bits */
 
124
  adts_header[2] = obj_type << 6;
 
125
  /* rate index over next 4 bits */
 
126
  adts_header[2] |= (rate_idx << 2);
 
127
  /* channels over last 2 bits */
 
128
  adts_header[2] |= (channels & 0x4) >> 2;
 
129
  /* channels continued over next 2 bits + 4 bits at zero */
 
130
  adts_header[3] = (channels & 0x3) << 6;
 
131
  /* frame size over last 2 bits */
 
132
  adts_header[3] |= (GST_BUFFER_SIZE (out_buf) & 0x1800) >> 11;
 
133
  /* frame size continued over full byte */
 
134
  adts_header[4] = (GST_BUFFER_SIZE (out_buf) & 0x1FF8) >> 3;
 
135
  /* frame size continued first 3 bits */
 
136
  adts_header[5] = (GST_BUFFER_SIZE (out_buf) & 0x7) << 5;
 
137
  /* buffer fullness (0x7FF for VBR) over 5 last bits */
 
138
  adts_header[5] |= 0x1F;
 
139
  /* buffer fullness (0x7FF for VBR) continued over 6 first bits + 2 zeros for
 
140
   * number of raw data blocks */
 
141
  adts_header[6] = 0xFC;
 
142
 
 
143
  /* Insert ADTS header */
 
144
  memcpy (GST_BUFFER_DATA (out_buf) + out_offset, adts_header, 7);
 
145
  out_offset += 7;
 
146
 
 
147
  /* Now copy complete frame */
 
148
  memcpy (GST_BUFFER_DATA (out_buf) + out_offset, GST_BUFFER_DATA (buf),
 
149
      GST_BUFFER_SIZE (buf));
 
150
 
 
151
  return out_buf;
 
152
}