~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavcodec/vda.c

  • Committer: Gauvain Pocentek
  • Date: 2012-03-06 11:59:12 UTC
  • mfrom: (66.1.15 precise)
  • Revision ID: gauvain@pocentek.net-20120306115912-h9d6kt9j0l532oo5
* Merge from Ubuntu:
  - put back faac support
  - recommends apport-hooks-medibuntu
  - change Maintainer, Uploaders & Vcs-* fields.
* New upstream snapshot
* upload to unstable
* Build against external libmpeg2
* drop 51_FTBFS_arm.patch again
* no longer build depend on libcdparanoia-dev on the Hurd
* Fix FTBFS on the hurd.
  Thanks to Samuel Thibault <sthibault@debian.org> (Closes: #654974)
* Fix FTBFS on arm
* New upstream snapshot, Closes: #650339, #643621, #481807
* Imported Upstream version 1.0~rc4+svn34492
* Bump standards version
* Bump dependency on libav >= 4:0.8~, Closes: #653887
* Fix build-indep
* Build mplayer-gui again, Closes: #568514
* Drop debian/all-lang-config-mak.sh, no longer needed
* include .dfsg1 in version number
* remove get-orig-source target
* no longer prune compiler flags from the environment
* No longer advertise nor build 3fdx, mga and dxr3 backends,
  Closes: #496106, #442181, #533546
* beautify mplayer version identification string
* Brown paperbag upload.
* Next try to fix build failure on sparce after recent binutils change.
* Brown paperbag upload.
* Really fix build failure on sparc after recent binutils change.
* Properly set Replaces/Conflicts on mplayer2{,-dbg} to avoid
  file overwrite errors.
* Adjust versioning of mplayer listed in the mplayer-dbg's Depends field.
* Fix build failure on sparc after recent binutils change.
* Urgency medium bumped because of RC-level bugfix
  and speeding up x264 transition.
* Update to my @debian.org email.
* Upload to unstable
* Enable joystick support on Linux only, Closes: #638408
* Rebuild fixes toolchain issue on arm, Closes: #637077
* New upstream snapshot
* following the discussion started by Diego Biurrun <diego@biurrun.de>
  in debian-devel, I have prepared a new packaging of 'mplayer'
  (with code that comes from CVS)
* the upstream tar.bz cannot be distributed by Debian, since it contains
   CSS code; so I am repackaging it 
* I have tried my best to address all known issues:
  - the package contains the detailed Copyright made by Diego Biurrun 
  - the package does not contain CSS code, or  AFAIK other code on which 
     there is active patent enforcement
  - there is a script  debian/cvs-changelog.sh  that shows all changes
     done to files included in this source.
    This should comply with GPLv2 sec 2.a  (in spirit if not in letter)
    For this reason, the source code contains CVS directories.
* needs   make (>= 3.80) for 'html-chunked-$(1)' in DOCS/xml/Makefile

* some corrections, as suggested Diego Biurrun
  - binary codecs should go into /usr/lib/codecs (upstream default)
  - better template 'mplayer/install_codecs'
  - an empty 'font=' in mplayer.conf breaks mplayer: postinst corrected
* correction in 'mplayer/cfgnote'
* better mplayer.postinst and mplayer.config

* New upstream release
* better debian/copyright file
* do not ship a skin
* New upstream release
* changed DEB_BUILD_OPTIONS to DEB_BUILD_CONFIGURE ,
  DEB_BUILD_OPTIONS is used as in debian policy
* use gcc-3.4
* changed xlibs-dev to a long list of dependencies, for Debian/etch
* try to adhere to  http://www.mplayerhq.hu/DOCS/tech/binary-packaging.txt
  (see README.Debian for details)
* removed dependency on xlibmesa-dev, disabled opengl
* New upstream release
* Simon McVittie <hacks@pseudorandom.co.uk> wonderful work:
- Work around Debian bug #267442 (glibc's sys/uio.h and gcc's altivec.h have
  conflicting uses for __vector) by re-ordering #includes
- Fix potential symlink attack in ./configure
- Disable support for binary codecs on platforms for which those codecs
  aren't available; also disable the corresponding Debconf note when it's
  inappropriate
- Changed Build-Depends: so it works in pbuilder
- Explicitly build-depend on libjpeg62-dev, libfontconfig1-dev,
  libungif4-dev 
- Tweak debian/rules to avoid certain errors being ignored
- Use --language=all
* provide a target  'debian/rules get-orig-source' 
  that recreates the orig.tar.gz ; then use the above orig.tar.gz
* rewrote some parts of debian/rules
* don't clean and recompile docs if upstream ships them
* mplayer-doc was shipping too much stuff
* translated man pages where not installed properly
* compile with libdv4-dev
* correct README.Debian
* Forgot build-dep on libtheora
* Must not depend on libxvidcore
* New upstream release
* new release.
* rc1 to become 0.90
* new pre-release
* new pre-release
* gtk bug fixed.
* new release.
* version bumped
* 0.60 pre2 release
* 0.60 pre-release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * VDA hardware acceleration
 
3
 *
 
4
 * copyright (c) 2011 Sebastien Zwickert
 
5
 *
 
6
 * This file is part of Libav.
 
7
 *
 
8
 * Libav is free software; you can redistribute it and/or
 
9
 * modify it under the terms of the GNU Lesser General Public
 
10
 * License as published by the Free Software Foundation; either
 
11
 * version 2.1 of the License, or (at your option) any later version.
 
12
 *
 
13
 * Libav is distributed in the hope that it will be useful,
 
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
16
 * Lesser General Public License for more details.
 
17
 *
 
18
 * You should have received a copy of the GNU Lesser General Public
 
19
 * License along with Libav; if not, write to the Free Software
 
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
21
 */
 
22
 
 
23
#include <pthread.h>
 
24
#include <CoreFoundation/CFDictionary.h>
 
25
#include <CoreFoundation/CFNumber.h>
 
26
#include <CoreFoundation/CFData.h>
 
27
#include <CoreFoundation/CFString.h>
 
28
 
 
29
#include "libavutil/avutil.h"
 
30
#include "vda_internal.h"
 
31
 
 
32
/* helper to create a dictionary according to the given pts */
 
33
static CFDictionaryRef vda_dictionary_with_pts(int64_t i_pts)
 
34
{
 
35
    CFStringRef key           = CFSTR("FF_VDA_DECODER_PTS_KEY");
 
36
    CFNumberRef value         = CFNumberCreate(kCFAllocatorDefault,
 
37
                                               kCFNumberSInt64Type, &i_pts);
 
38
    CFDictionaryRef user_info = CFDictionaryCreate(kCFAllocatorDefault,
 
39
                                                   (const void **)&key,
 
40
                                                   (const void **)&value,
 
41
                                                   1,
 
42
                                                   &kCFTypeDictionaryKeyCallBacks,
 
43
                                                   &kCFTypeDictionaryValueCallBacks);
 
44
    CFRelease(value);
 
45
    return user_info;
 
46
}
 
47
 
 
48
/* helper to retrieve the pts from the given dictionary */
 
49
static int64_t vda_pts_from_dictionary(CFDictionaryRef user_info)
 
50
{
 
51
    CFNumberRef pts;
 
52
    int64_t outValue = 0;
 
53
 
 
54
    if (!user_info)
 
55
        return 0;
 
56
 
 
57
    pts = CFDictionaryGetValue(user_info, CFSTR("FF_VDA_DECODER_PTS_KEY"));
 
58
 
 
59
    if (pts)
 
60
        CFNumberGetValue(pts, kCFNumberSInt64Type, &outValue);
 
61
 
 
62
    return outValue;
 
63
}
 
64
 
 
65
/* Remove and release all frames from the queue. */
 
66
static void vda_clear_queue(struct vda_context *vda_ctx)
 
67
{
 
68
    vda_frame *top_frame;
 
69
 
 
70
    pthread_mutex_lock(&vda_ctx->queue_mutex);
 
71
 
 
72
    while (vda_ctx->queue) {
 
73
        top_frame      = vda_ctx->queue;
 
74
        vda_ctx->queue = top_frame->next_frame;
 
75
        ff_vda_release_vda_frame(top_frame);
 
76
    }
 
77
 
 
78
    pthread_mutex_unlock(&vda_ctx->queue_mutex);
 
79
}
 
80
 
 
81
/* Decoder callback that adds the VDA frame to the queue in display order. */
 
82
static void vda_decoder_callback(void *vda_hw_ctx,
 
83
                                 CFDictionaryRef user_info,
 
84
                                 OSStatus status,
 
85
                                 uint32_t infoFlags,
 
86
                                 CVImageBufferRef image_buffer)
 
87
{
 
88
    struct vda_context *vda_ctx = vda_hw_ctx;
 
89
    vda_frame *new_frame;
 
90
    vda_frame *queue_walker;
 
91
 
 
92
    if (!image_buffer)
 
93
        return;
 
94
 
 
95
    if (vda_ctx->cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer))
 
96
        return;
 
97
 
 
98
    if (!(new_frame = av_mallocz(sizeof(vda_frame))))
 
99
        return;
 
100
    new_frame->next_frame = NULL;
 
101
    new_frame->cv_buffer  = CVPixelBufferRetain(image_buffer);
 
102
    new_frame->pts        = vda_pts_from_dictionary(user_info);
 
103
 
 
104
    pthread_mutex_lock(&vda_ctx->queue_mutex);
 
105
 
 
106
    queue_walker = vda_ctx->queue;
 
107
 
 
108
    if (!queue_walker || new_frame->pts < queue_walker->pts) {
 
109
        /* we have an empty queue, or this frame earlier than the current queue head */
 
110
        new_frame->next_frame = queue_walker;
 
111
        vda_ctx->queue        = new_frame;
 
112
    } else {
 
113
        /* walk the queue and insert this frame where it belongs in display order */
 
114
        vda_frame *next_frame;
 
115
        while (1) {
 
116
            next_frame = queue_walker->next_frame;
 
117
            if (!next_frame || new_frame->pts < next_frame->pts) {
 
118
                new_frame->next_frame    = next_frame;
 
119
                queue_walker->next_frame = new_frame;
 
120
                break;
 
121
            }
 
122
            queue_walker = next_frame;
 
123
        }
 
124
    }
 
125
 
 
126
    pthread_mutex_unlock(&vda_ctx->queue_mutex);
 
127
}
 
128
 
 
129
int ff_vda_create_decoder(struct vda_context *vda_ctx,
 
130
                          uint8_t *extradata,
 
131
                          int extradata_size)
 
132
{
 
133
    OSStatus status = kVDADecoderNoErr;
 
134
    CFNumberRef height;
 
135
    CFNumberRef width;
 
136
    CFNumberRef format;
 
137
    CFDataRef avc_data;
 
138
    CFMutableDictionaryRef config_info;
 
139
    CFMutableDictionaryRef buffer_attributes;
 
140
    CFMutableDictionaryRef io_surface_properties;
 
141
    CFNumberRef cv_pix_fmt;
 
142
 
 
143
    pthread_mutex_init(&vda_ctx->queue_mutex, NULL);
 
144
 
 
145
    config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
 
146
                                            4,
 
147
                                            &kCFTypeDictionaryKeyCallBacks,
 
148
                                            &kCFTypeDictionaryValueCallBacks);
 
149
 
 
150
    height   = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->height);
 
151
    width    = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->width);
 
152
    format   = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->format);
 
153
    avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size);
 
154
 
 
155
    CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
 
156
    CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
 
157
    CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format);
 
158
    CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data);
 
159
 
 
160
    buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
 
161
                                                  2,
 
162
                                                  &kCFTypeDictionaryKeyCallBacks,
 
163
                                                  &kCFTypeDictionaryValueCallBacks);
 
164
    io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
 
165
                                                      0,
 
166
                                                      &kCFTypeDictionaryKeyCallBacks,
 
167
                                                      &kCFTypeDictionaryValueCallBacks);
 
168
    cv_pix_fmt      = CFNumberCreate(kCFAllocatorDefault,
 
169
                                     kCFNumberSInt32Type,
 
170
                                     &vda_ctx->cv_pix_fmt_type);
 
171
    CFDictionarySetValue(buffer_attributes,
 
172
                         kCVPixelBufferPixelFormatTypeKey,
 
173
                         cv_pix_fmt);
 
174
    CFDictionarySetValue(buffer_attributes,
 
175
                         kCVPixelBufferIOSurfacePropertiesKey,
 
176
                         io_surface_properties);
 
177
 
 
178
    status = VDADecoderCreate(config_info,
 
179
                              buffer_attributes,
 
180
                              vda_decoder_callback,
 
181
                              vda_ctx,
 
182
                              &vda_ctx->decoder);
 
183
 
 
184
    CFRelease(height);
 
185
    CFRelease(width);
 
186
    CFRelease(format);
 
187
    CFRelease(avc_data);
 
188
    CFRelease(config_info);
 
189
    CFRelease(io_surface_properties);
 
190
    CFRelease(cv_pix_fmt);
 
191
    CFRelease(buffer_attributes);
 
192
 
 
193
    if (kVDADecoderNoErr != status)
 
194
        return status;
 
195
 
 
196
    return 0;
 
197
}
 
198
 
 
199
int ff_vda_destroy_decoder(struct vda_context *vda_ctx)
 
200
{
 
201
    OSStatus status = kVDADecoderNoErr;
 
202
 
 
203
    if (vda_ctx->decoder)
 
204
        status = VDADecoderDestroy(vda_ctx->decoder);
 
205
 
 
206
    vda_clear_queue(vda_ctx);
 
207
 
 
208
    pthread_mutex_destroy(&vda_ctx->queue_mutex);
 
209
 
 
210
    if (kVDADecoderNoErr != status)
 
211
        return status;
 
212
 
 
213
    return 0;
 
214
}
 
215
 
 
216
vda_frame *ff_vda_queue_pop(struct vda_context *vda_ctx)
 
217
{
 
218
    vda_frame *top_frame;
 
219
 
 
220
    if (!vda_ctx->queue)
 
221
        return NULL;
 
222
 
 
223
    pthread_mutex_lock(&vda_ctx->queue_mutex);
 
224
    top_frame      = vda_ctx->queue;
 
225
    vda_ctx->queue = top_frame->next_frame;
 
226
    pthread_mutex_unlock(&vda_ctx->queue_mutex);
 
227
 
 
228
    return top_frame;
 
229
}
 
230
 
 
231
void ff_vda_release_vda_frame(vda_frame *frame)
 
232
{
 
233
    if (frame) {
 
234
        CVPixelBufferRelease(frame->cv_buffer);
 
235
        av_freep(&frame);
 
236
    }
 
237
}
 
238
 
 
239
int ff_vda_decoder_decode(struct vda_context *vda_ctx,
 
240
                          uint8_t *bitstream,
 
241
                          int bitstream_size,
 
242
                          int64_t frame_pts)
 
243
{
 
244
    OSStatus status = kVDADecoderNoErr;
 
245
    CFDictionaryRef user_info;
 
246
    CFDataRef coded_frame;
 
247
 
 
248
    coded_frame = CFDataCreate(kCFAllocatorDefault, bitstream, bitstream_size);
 
249
    user_info   = vda_dictionary_with_pts(frame_pts);
 
250
    status      = VDADecoderDecode(vda_ctx->decoder, 0, coded_frame, user_info);
 
251
 
 
252
    CFRelease(user_info);
 
253
    CFRelease(coded_frame);
 
254
 
 
255
    if (kVDADecoderNoErr != status)
 
256
        return status;
 
257
 
 
258
    return 0;
 
259
}