1 Subject: Collected Debian patches for libhybris
2 Author: Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
4 The libhybris package is maintained in Git rather than maintaining
5 patches as separate files, and separating the patches doesn't seem to
6 be worth the effort. They are therefore all included in this single
9 For full commit history and separated commits, see the packaging Git
12 +++ libhybris-0.1.0+git20131207+e452e83/compat/Android.common.mk
14 +# define ANDROID_VERSION MAJOR, MINOR and PATCH
16 +ANDROID_VERSION_MAJOR := $(word 1, $(subst ., , $(PLATFORM_VERSION)))
17 +ANDROID_VERSION_MINOR := $(word 2, $(subst ., , $(PLATFORM_VERSION)))
18 +ANDROID_VERSION_PATCH := $(word 3, $(subst ., , $(PLATFORM_VERSION)))
21 + -DANDROID_VERSION_MAJOR=$(ANDROID_VERSION_MAJOR) \
22 + -DANDROID_VERSION_MINOR=$(ANDROID_VERSION_MINOR) \
23 + -DANDROID_VERSION_PATCH=$(ANDROID_VERSION_PATCH)
24 --- libhybris-0.1.0+git20131207+e452e83.orig/compat/camera/Android.mk
25 +++ libhybris-0.1.0+git20131207+e452e83/compat/camera/Android.mk
27 LOCAL_PATH:= $(call my-dir)
29 +include $(LOCAL_PATH)/../Android.common.mk
31 HYBRIS_PATH := $(LOCAL_PATH)/../../hybris
33 --- libhybris-0.1.0+git20131207+e452e83.orig/compat/camera/camera_compatibility_layer.cpp
34 +++ libhybris-0.1.0+git20131207+e452e83/compat/camera/camera_compatibility_layer.cpp
36 #include <binder/ProcessState.h>
37 #include <camera/Camera.h>
38 #include <camera/CameraParameters.h>
39 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
40 #include <gui/SurfaceTexture.h>
42 +#include <gui/GLConsumer.h>
44 #include <ui/GraphicBuffer.h>
46 +#include <GLES2/gl2.h>
47 +#include <GLES2/gl2ext.h>
50 #define LOG_TAG "CameraCompatibilityLayer"
51 #include <utils/KeyedVector.h>
52 #include <utils/Log.h>
53 +#include <utils/String16.h>
55 #define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
57 -// From android::SurfaceTexture::FrameAvailableListener
58 +// From android::GLConsumer::FrameAvailableListener
59 void CameraControl::onFrameAvailable()
62 @@ -170,7 +178,11 @@ CameraControl* android_camera_connect_to
64 CameraControl* cc = new CameraControl();
65 cc->listener = listener;
66 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR>=3
67 + cc->camera = android::Camera::connect(camera_id, android::String16("hybris"), android::Camera::USE_CALLING_UID);
69 cc->camera = android::Camera::connect(camera_id);
72 if (cc->camera == NULL)
74 @@ -511,30 +523,57 @@ void android_camera_set_preview_texture(
77 static const bool allow_synchronous_mode = false;
78 + static const bool is_controlled_by_app = true;
80 android::sp<android::NativeBufferAlloc> native_alloc(
81 new android::NativeBufferAlloc()
84 android::sp<android::BufferQueue> buffer_queue(
85 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
86 new android::BufferQueue(false, NULL, native_alloc)
88 + new android::BufferQueue(NULL, native_alloc)
92 if (control->preview_texture == NULL) {
93 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
94 control->preview_texture = android::sp<android::SurfaceTexture>(
95 new android::SurfaceTexture(
97 + control->preview_texture = android::sp<android::GLConsumer>(
98 + new android::GLConsumer(
100 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
102 allow_synchronous_mode,
103 GL_TEXTURE_EXTERNAL_OES,
109 + GL_TEXTURE_EXTERNAL_OES,
111 + is_controlled_by_app));
115 control->preview_texture->setFrameAvailableListener(
116 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
117 android::sp<android::SurfaceTexture::FrameAvailableListener>(control));
119 + android::sp<android::GLConsumer::FrameAvailableListener>(control));
121 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
122 control->camera->setPreviewTexture(control->preview_texture->getBufferQueue());
124 + control->camera->setPreviewTarget(buffer_queue);
128 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
129 void android_camera_set_preview_surface(CameraControl* control, SfSurface* surface)
132 @@ -544,6 +583,7 @@ void android_camera_set_preview_surface(
133 android::Mutex::Autolock al(control->guard);
134 control->camera->setPreviewDisplay(surface->surface);
138 void android_camera_start_preview(CameraControl* control)
140 --- libhybris-0.1.0+git20131207+e452e83.orig/compat/input/Android.mk
141 +++ libhybris-0.1.0+git20131207+e452e83/compat/input/Android.mk
142 @@ -18,6 +18,11 @@ LOCAL_SHARED_LIBRARIES := \
146 +HAS_LIBINPUTSERVICE := $(shell test $(ANDROID_VERSION_MAJOR) -eq 4 -a $(ANDROID_VERSION_MINOR) -gt 2 && echo true)
147 +ifeq ($(HAS_LIBINPUTSERVICE),true)
148 +LOCAL_SHARED_LIBRARIES += libinputservice
151 LOCAL_C_INCLUDES := \
152 $(HYBRIS_PATH)/include \
153 external/skia/include/core \
155 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/Android.mk
157 +LOCAL_PATH:= $(call my-dir)
158 +include $(CLEAR_VARS)
159 +include $(LOCAL_PATH)/../Android.common.mk
161 +HYBRIS_PATH := $(LOCAL_PATH)/../../hybris
163 +LOCAL_CFLAGS += -std=gnu++0x
166 + media_compatibility_layer.cpp \
167 + media_codec_layer.cpp \
168 + media_codec_list.cpp \
169 + media_format_layer.cpp \
170 + surface_texture_client_hybris.cpp \
171 + recorder_compatibility_layer.cpp
173 +LOCAL_MODULE:= libmedia_compat_layer
174 +LOCAL_MODULE_TAGS := optional
176 +LOCAL_SHARED_LIBRARIES := \
185 + libstagefright_foundation \
190 +LOCAL_C_INCLUDES := \
191 + $(HYBRIS_PATH)/include \
192 + frameworks/base/media/libstagefright/include \
193 + frameworks/base/include/media/stagefright \
194 + frameworks/base/include/media
196 +include $(BUILD_SHARED_LIBRARY)
198 +include $(CLEAR_VARS)
199 +include $(LOCAL_PATH)/../Android.common.mk
202 + direct_media_test.cpp
204 +LOCAL_MODULE:= direct_media_test
205 +LOCAL_MODULE_TAGS := optional
207 +LOCAL_C_INCLUDES := \
208 + $(HYBRIS_PATH)/include \
210 + bionic/libstdc++/include \
211 + external/gtest/include \
212 + external/stlport/stlport \
213 + external/skia/include/core \
214 + frameworks/base/include
216 +LOCAL_SHARED_LIBRARIES := \
217 + libis_compat_layer \
218 + libsf_compat_layer \
219 + libmedia_compat_layer \
229 +include $(BUILD_EXECUTABLE)
231 +include $(CLEAR_VARS)
232 +include $(LOCAL_PATH)/../Android.common.mk
234 +LOCAL_CFLAGS += -Wno-multichar -D SIMPLE_PLAYER -std=gnu++0x
237 + media_codec_layer.cpp \
238 + media_codec_list.cpp \
239 + media_format_layer.cpp \
243 +LOCAL_SHARED_LIBRARIES := \
245 + libstagefright_foundation \
254 +LOCAL_C_INCLUDES:= \
255 + $(HYBRIS_PATH)/include \
256 + frameworks/av/media/libstagefright \
257 + frameworks/native/include/media/openmax \
258 + frameworks/base/media/libstagefright/include \
259 + frameworks/base/include/media/stagefright \
260 + frameworks/base/include/media
262 +LOCAL_MODULE:= codec
263 +LOCAL_MODULE_TAGS := optional
265 +include $(BUILD_EXECUTABLE)
267 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/SimplePlayer.cpp
270 + * Copyright (C) 2012 The Android Open Source Project
272 + * Licensed under the Apache License, Version 2.0 (the "License");
273 + * you may not use this file except in compliance with the License.
274 + * You may obtain a copy of the License at
276 + * http://www.apache.org/licenses/LICENSE-2.0
278 + * Unless required by applicable law or agreed to in writing, software
279 + * distributed under the License is distributed on an "AS IS" BASIS,
280 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
281 + * See the License for the specific language governing permissions and
282 + * limitations under the License.
285 +//#define LOG_NDEBUG 0
286 +#define LOG_TAG "SimplePlayer"
287 +#include <utils/Log.h>
289 +#include "SimplePlayer.h"
291 +#include <gui/Surface.h>
292 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
293 +#include <gui/SurfaceTextureClient.h>
295 +#include <media/AudioTrack.h>
296 +#include <media/ICrypto.h>
297 +#include <media/stagefright/foundation/ABuffer.h>
298 +#include <media/stagefright/foundation/ADebug.h>
299 +#include <media/stagefright/foundation/AMessage.h>
300 +#include <media/stagefright/MediaCodec.h>
301 +#include <media/stagefright/MediaErrors.h>
302 +#include <media/stagefright/NativeWindowWrapper.h>
303 +#include <media/stagefright/NuMediaExtractor.h>
305 +#define USE_MEDIA_CODEC_LAYER
309 +SimplePlayer::SimplePlayer()
310 + : mState(UNINITIALIZED),
311 + mDoMoreStuffGeneration(0),
312 + mStartTimeRealUs(-1ll) {
315 +SimplePlayer::~SimplePlayer() {
319 +status_t PostAndAwaitResponse(
320 + const sp<AMessage> &msg, sp<AMessage> *response) {
321 + status_t err = msg->postAndAwaitResponse(response);
322 + printf("%s\n", __PRETTY_FUNCTION__);
328 + if (!(*response)->findInt32("err", &err)) {
334 +status_t SimplePlayer::setDataSource(const char *path) {
335 + sp<AMessage> msg = new AMessage(kWhatSetDataSource, id());
336 + msg->setString("path", path);
337 + sp<AMessage> response;
338 + return PostAndAwaitResponse(msg, &response);
341 +status_t SimplePlayer::setSurface(const sp<ISurfaceTexture> &surfaceTexture) {
342 + sp<AMessage> msg = new AMessage(kWhatSetSurface, id());
344 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
345 + sp<SurfaceTextureClient> surfaceTextureClient;
346 + if (surfaceTexture != NULL) {
347 + surfaceTextureClient = new SurfaceTextureClient(surfaceTexture);
350 + sp<Surface> surfaceTextureClient;
351 + if (surfaceTexture != NULL) {
352 + surfaceTextureClient = new Surface(surfaceTexture);
357 + "native-window", new NativeWindowWrapper(surfaceTextureClient));
359 + sp<AMessage> response;
360 + return PostAndAwaitResponse(msg, &response);
363 +status_t SimplePlayer::prepare() {
364 + sp<AMessage> msg = new AMessage(kWhatPrepare, id());
365 + sp<AMessage> response;
366 + return PostAndAwaitResponse(msg, &response);
369 +status_t SimplePlayer::start() {
370 + printf("%s\n", __PRETTY_FUNCTION__);
371 + sp<AMessage> msg = new AMessage(kWhatStart, id());
372 + sp<AMessage> response;
373 + return PostAndAwaitResponse(msg, &response);
376 +status_t SimplePlayer::stop() {
377 + sp<AMessage> msg = new AMessage(kWhatStop, id());
378 + sp<AMessage> response;
379 + return PostAndAwaitResponse(msg, &response);
382 +status_t SimplePlayer::reset() {
383 + sp<AMessage> msg = new AMessage(kWhatReset, id());
384 + sp<AMessage> response;
385 + return PostAndAwaitResponse(msg, &response);
388 +void SimplePlayer::onMessageReceived(const sp<AMessage> &msg) {
389 + switch (msg->what()) {
390 + case kWhatSetDataSource:
393 + if (mState != UNINITIALIZED) {
394 + err = INVALID_OPERATION;
396 + CHECK(msg->findString("path", &mPath));
397 + mState = UNPREPARED;
401 + CHECK(msg->senderAwaitsResponse(&replyID));
403 + sp<AMessage> response = new AMessage;
404 + response->setInt32("err", err);
405 + response->postReply(replyID);
409 + case kWhatSetSurface:
412 + if (mState != UNPREPARED) {
413 + err = INVALID_OPERATION;
416 + CHECK(msg->findObject("native-window", &obj));
418 + mNativeWindow = static_cast<NativeWindowWrapper *>(obj.get());
424 + CHECK(msg->senderAwaitsResponse(&replyID));
426 + sp<AMessage> response = new AMessage;
427 + response->setInt32("err", err);
428 + response->postReply(replyID);
435 + if (mState != UNPREPARED) {
436 + err = INVALID_OPERATION;
446 + CHECK(msg->senderAwaitsResponse(&replyID));
448 + sp<AMessage> response = new AMessage;
449 + response->setInt32("err", err);
450 + response->postReply(replyID);
458 + if (mState == UNPREPARED) {
467 + if (mState != STOPPED) {
468 + err = INVALID_OPERATION;
479 + CHECK(msg->senderAwaitsResponse(&replyID));
481 + sp<AMessage> response = new AMessage;
482 + response->setInt32("err", err);
483 + response->postReply(replyID);
491 + if (mState != STARTED) {
492 + err = INVALID_OPERATION;
502 + CHECK(msg->senderAwaitsResponse(&replyID));
504 + sp<AMessage> response = new AMessage;
505 + response->setInt32("err", err);
506 + response->postReply(replyID);
514 + if (mState == STARTED) {
515 + CHECK_EQ(onStop(), (status_t)OK);
519 + if (mState == STOPPED) {
521 + mState = UNINITIALIZED;
525 + CHECK(msg->senderAwaitsResponse(&replyID));
527 + sp<AMessage> response = new AMessage;
528 + response->setInt32("err", err);
529 + response->postReply(replyID);
533 + case kWhatDoMoreStuff:
535 + int32_t generation;
536 + CHECK(msg->findInt32("generation", &generation));
538 + if (generation != mDoMoreStuffGeneration) {
542 + status_t err = onDoMoreStuff();
545 + msg->post(10000ll);
555 +status_t SimplePlayer::onPrepare() {
556 + CHECK_EQ(mState, UNPREPARED);
557 + printf("%s\n", __PRETTY_FUNCTION__);
559 + mExtractor = new NuMediaExtractor;
561 + status_t err = mExtractor->setDataSource(mPath.c_str());
564 + mExtractor.clear();
568 + if (mCodecLooper == NULL) {
569 + mCodecLooper = new ALooper;
570 + mCodecLooper->start();
573 + bool haveAudio = false;
574 + bool haveVideo = false;
575 + for (size_t i = 0; i < mExtractor->countTracks(); ++i) {
576 + sp<AMessage> format;
577 + status_t err = mExtractor->getTrackFormat(i, &format);
578 + CHECK_EQ(err, (status_t)OK);
581 + int32_t width = 0, height = 0, maxInputSize = 0;
582 + int64_t durationUs = 0;
583 + sp<ABuffer> csd0, csd1;
584 +#ifdef USE_MEDIA_CODEC_LAYER
585 + MediaFormat mformat;
587 + CHECK(format->findString("mime", &mime));
589 + if (!haveAudio && !strncasecmp(mime.c_str(), "audio/", 6)) {
590 + //haveAudio = true;
591 + printf("*** Have audio but skipping it!\n");
593 + } else if (!haveVideo && !strncasecmp(mime.c_str(), "video/", 6)) {
595 + CHECK(format->findInt32("width", &width));
596 + CHECK(format->findInt32("height", &height));
597 + CHECK(format->findInt64("durationUs", &durationUs));
598 + CHECK(format->findInt32("max-input-size", &maxInputSize));
599 + CHECK(format->findBuffer("csd-0", &csd0));
600 + CHECK(format->findBuffer("csd-1", &csd1));
601 +#ifdef USE_MEDIA_CODEC_LAYER
602 + mformat = media_format_create_video_format(mime.c_str(), width, height, durationUs, maxInputSize);
603 + media_format_set_byte_buffer(mformat, "csd-0", csd0->data(), csd0->size());
604 + media_format_set_byte_buffer(mformat, "csd-1", csd1->data(), csd1->size());
610 + err = mExtractor->selectTrack(i);
611 + CHECK_EQ(err, (status_t)OK);
613 + CodecState *state =
614 + &mStateByTrackIndex.editValueAt(
615 + mStateByTrackIndex.add(i, CodecState()));
617 + state->mNumFramesWritten = 0;
618 +#ifdef USE_MEDIA_CODEC_LAYER
619 + state->mCodecDelegate = media_codec_create_by_codec_type(mime.c_str());
620 + state->mCodec = media_codec_get(state->mCodecDelegate);
621 + CHECK(state->mCodecDelegate != NULL);
623 + state->mCodec = MediaCodec::CreateByType(
624 + mCodecLooper, mime.c_str(), false /* encoder */);
627 + CHECK(state->mCodec != NULL);
629 +#ifdef USE_MEDIA_CODEC_LAYER
630 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
631 + err = media_codec_configure(state->mCodecDelegate, mformat, mNativeWindow->getSurfaceTextureClient().get(), 0);
633 + err = media_codec_configure(state->mCodecDelegate, mformat, mNativeWindow->getSurface().get(), 0);
636 + err = state->mCodec->configure(
638 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
639 + mNativeWindow->getSurfaceTextureClient(),
641 + mNativeWindow->getSurface(),
647 + CHECK_EQ(err, (status_t)OK);
650 + sp<ABuffer> buffer;
651 + // Place the CSD data into the source buffer
652 + while (format->findBuffer(StringPrintf("csd-%d", j).c_str(), &buffer)) {
653 + state->mCSD.push_back(buffer);
659 + for (size_t i = 0; i < mStateByTrackIndex.size(); ++i) {
660 + CodecState *state = &mStateByTrackIndex.editValueAt(i);
662 +#ifdef USE_MEDIA_CODEC_LAYER
663 + status_t err = media_codec_start(state->mCodecDelegate);
665 + status_t err = state->mCodec->start();
667 + CHECK_EQ(err, (status_t)OK);
669 +#ifdef USE_MEDIA_CODEC_LAYER
670 + size_t nInputBuffers = media_codec_get_input_buffers_size(state->mCodecDelegate);
671 + ALOGD("nInputBuffers: %u", nInputBuffers);
672 + for (size_t i=0; i<nInputBuffers; i++)
674 + uint8_t *data = media_codec_get_nth_input_buffer(state->mCodecDelegate, i);
675 + CHECK(data != NULL);
676 + size_t size = media_codec_get_nth_input_buffer_capacity(state->mCodecDelegate, i);
677 + ALOGD("input buffer[%d] size: %d", i, size);
678 + sp<ABuffer> buf = new ABuffer(data, size);
679 + state->mBuffers[0].insertAt(new ABuffer(data, size), i);
682 + err = state->mCodec->getInputBuffers(&state->mBuffers[0]);
683 + CHECK_EQ(err, (status_t)OK);
686 + err = state->mCodec->getOutputBuffers(&state->mBuffers[1]);
687 + CHECK_EQ(err, (status_t)OK);
689 + for (size_t j = 0; j < state->mCSD.size(); ++j) {
690 + const sp<ABuffer> &srcBuffer = state->mCSD.itemAt(j);
693 +#ifdef USE_MEDIA_CODEC_LAYER
694 + err = media_codec_dequeue_input_buffer(state->mCodecDelegate, &index, -1ll);
696 + err = state->mCodec->dequeueInputBuffer(&index, -1ll);
698 + CHECK_EQ(err, (status_t)OK);
700 + const sp<ABuffer> &dstBuffer = state->mBuffers[0].itemAt(index);
702 + CHECK_LE(srcBuffer->size(), dstBuffer->capacity());
703 + dstBuffer->setRange(0, srcBuffer->size());
704 + memcpy(dstBuffer->data(), srcBuffer->data(), srcBuffer->size());
706 +#ifdef USE_MEDIA_CODEC_LAYER
707 + MediaCodecBufferInfo bufInfo;
708 + bufInfo.index = index;
709 + bufInfo.offset = 0;
710 + bufInfo.size = dstBuffer->size();
711 + bufInfo.presentation_time_us = 0ll;
712 + bufInfo.flags = MediaCodec::BUFFER_FLAG_CODECCONFIG;
714 + err = media_codec_queue_input_buffer(
715 + state->mCodecDelegate,
719 + err = state->mCodec->queueInputBuffer(
724 + MediaCodec::BUFFER_FLAG_CODECCONFIG);
726 + CHECK_EQ(err, (status_t)OK);
733 +status_t SimplePlayer::onStart() {
734 + CHECK_EQ(mState, STOPPED);
736 + mStartTimeRealUs = -1ll;
738 + sp<AMessage> msg = new AMessage(kWhatDoMoreStuff, id());
739 + msg->setInt32("generation", ++mDoMoreStuffGeneration);
745 +status_t SimplePlayer::onStop() {
746 + CHECK_EQ(mState, STARTED);
748 + ++mDoMoreStuffGeneration;
753 +status_t SimplePlayer::onReset() {
754 + CHECK_EQ(mState, STOPPED);
756 + for (size_t i = 0; i < mStateByTrackIndex.size(); ++i) {
757 + CodecState *state = &mStateByTrackIndex.editValueAt(i);
759 + CHECK_EQ(state->mCodec->release(), (status_t)OK);
762 + mStartTimeRealUs = -1ll;
764 + mStateByTrackIndex.clear();
765 + mCodecLooper.clear();
766 + mExtractor.clear();
767 + mNativeWindow.clear();
773 +status_t SimplePlayer::onDoMoreStuff() {
774 + ALOGV("onDoMoreStuff");
775 + for (size_t i = 0; i < mStateByTrackIndex.size(); ++i) {
776 + CodecState *state = &mStateByTrackIndex.editValueAt(i);
781 +#ifdef USE_MEDIA_CODEC_LAYER
782 + err = media_codec_dequeue_input_buffer(state->mCodecDelegate, &index, 0ll);
784 + err = state->mCodec->dequeueInputBuffer(&index);
788 + ALOGD("dequeued input buffer on track %d",
789 + mStateByTrackIndex.keyAt(i));
791 + state->mAvailInputBufferIndices.push_back(index);
793 + ALOGD("dequeueInputBuffer on track %d returned %d",
794 + mStateByTrackIndex.keyAt(i), err);
796 + } while (err == OK);
799 +#ifdef USE_MEDIA_CODEC_LAYER
801 + MediaCodecBufferInfo bufInfo;
802 + err = media_codec_dequeue_output_buffer(
803 + state->mCodecDelegate,
807 + info.mIndex = bufInfo.index;
808 + info.mOffset = bufInfo.offset;
809 + info.mSize = bufInfo.size;
810 + info.mPresentationTimeUs = bufInfo.presentation_time_us;
811 + info.mFlags = bufInfo.flags;
815 + err = state->mCodec->dequeueOutputBuffer(
819 + &info.mPresentationTimeUs,
824 + ALOGV("dequeued output buffer on track %d",
825 + mStateByTrackIndex.keyAt(i));
827 + state->mAvailOutputBufferInfos.push_back(info);
828 + } else if (err == INFO_FORMAT_CHANGED) {
829 + err = onOutputFormatChanged(mStateByTrackIndex.keyAt(i), state);
830 + CHECK_EQ(err, (status_t)OK);
831 + } else if (err == INFO_OUTPUT_BUFFERS_CHANGED) {
832 + err = state->mCodec->getOutputBuffers(&state->mBuffers[1]);
833 + CHECK_EQ(err, (status_t)OK);
835 + ALOGV("dequeueOutputBuffer on track %d returned %d",
836 + mStateByTrackIndex.keyAt(i), err);
839 + || err == INFO_FORMAT_CHANGED
840 + || err == INFO_OUTPUT_BUFFERS_CHANGED);
845 + status_t err = mExtractor->getSampleTrackIndex(&trackIndex);
848 + ALOGI("encountered input EOS.");
851 + CodecState *state = &mStateByTrackIndex.editValueFor(trackIndex);
853 + if (state->mAvailInputBufferIndices.empty()) {
857 + size_t index = *state->mAvailInputBufferIndices.begin();
858 + state->mAvailInputBufferIndices.erase(
859 + state->mAvailInputBufferIndices.begin());
861 + const sp<ABuffer> &dstBuffer =
862 + state->mBuffers[0].itemAt(index);
864 + err = mExtractor->readSampleData(dstBuffer);
865 + CHECK_EQ(err, (status_t)OK);
868 + CHECK_EQ(mExtractor->getSampleTime(&timeUs), (status_t)OK);
870 +#ifdef USE_MEDIA_CODEC_LAYER
871 + MediaCodecBufferInfo bufInfo;
872 + bufInfo.index = index;
873 + bufInfo.offset = dstBuffer->offset();
874 + bufInfo.size = dstBuffer->size();
875 + bufInfo.presentation_time_us = timeUs;
878 + err = media_codec_queue_input_buffer(
879 + state->mCodecDelegate,
883 + err = state->mCodec->queueInputBuffer(
885 + dstBuffer->offset(),
890 + CHECK_EQ(err, (status_t)OK);
892 + ALOGV("enqueued input data on track %d", trackIndex);
894 + err = mExtractor->advance();
895 + CHECK_EQ(err, (status_t)OK);
899 + int64_t nowUs = ALooper::GetNowUs();
901 + if (mStartTimeRealUs < 0ll) {
902 + mStartTimeRealUs = nowUs + 1000000ll;
905 + for (size_t i = 0; i < mStateByTrackIndex.size(); ++i) {
906 + CodecState *state = &mStateByTrackIndex.editValueAt(i);
908 + while (!state->mAvailOutputBufferInfos.empty()) {
909 + BufferInfo *info = &*state->mAvailOutputBufferInfos.begin();
911 + int64_t whenRealUs = info->mPresentationTimeUs + mStartTimeRealUs;
912 + int64_t lateByUs = nowUs - whenRealUs;
914 + if (lateByUs > -10000ll) {
915 + bool release = true;
917 + if (lateByUs > 30000ll) {
918 + ALOGI("track %d buffer late by %lld us, dropping.",
919 + mStateByTrackIndex.keyAt(i), lateByUs);
920 + state->mCodec->releaseOutputBuffer(info->mIndex);
922 + if (state->mAudioTrack != NULL) {
923 + const sp<ABuffer> &srcBuffer =
924 + state->mBuffers[1].itemAt(info->mIndex);
926 + renderAudio(state, info, srcBuffer);
928 + if (info->mSize > 0) {
934 +#ifdef USE_MEDIA_CODEC_LAYER
935 + ALOGD("Rendering output buffer index %d and releasing", info->mIndex);
936 + state->mCodec->renderOutputBufferAndRelease(
939 + ALOGD("Releasing output buffer index %d", info->mIndex);
940 + state->mCodec->releaseOutputBuffer(info->mIndex);
946 + state->mAvailOutputBufferInfos.erase(
947 + state->mAvailOutputBufferInfos.begin());
954 + ALOGV("track %d buffer early by %lld us.",
955 + mStateByTrackIndex.keyAt(i), -lateByUs);
964 +status_t SimplePlayer::onOutputFormatChanged(
965 + size_t trackIndex, CodecState *state) {
966 + sp<AMessage> format;
967 + status_t err = state->mCodec->getOutputFormat(&format);
974 + CHECK(format->findString("mime", &mime));
976 + if (!strncasecmp(mime.c_str(), "audio/", 6)) {
977 + int32_t channelCount;
978 + int32_t sampleRate;
979 + CHECK(format->findInt32("channel-count", &channelCount));
980 + CHECK(format->findInt32("sample-rate", &sampleRate));
982 + state->mAudioTrack = new AudioTrack(
983 + AUDIO_STREAM_MUSIC,
985 + AUDIO_FORMAT_PCM_16_BIT,
986 + audio_channel_out_mask_from_count(channelCount),
989 + state->mNumFramesWritten = 0;
995 +void SimplePlayer::renderAudio(
996 + CodecState *state, BufferInfo *info, const sp<ABuffer> &buffer) {
997 + CHECK(state->mAudioTrack != NULL);
999 + if (state->mAudioTrack->stopped()) {
1000 + state->mAudioTrack->start();
1003 + uint32_t numFramesPlayed;
1004 + CHECK_EQ(state->mAudioTrack->getPosition(&numFramesPlayed), (status_t)OK);
1006 + uint32_t numFramesAvailableToWrite =
1007 + state->mAudioTrack->frameCount()
1008 + - (state->mNumFramesWritten - numFramesPlayed);
1010 + size_t numBytesAvailableToWrite =
1011 + numFramesAvailableToWrite * state->mAudioTrack->frameSize();
1013 + size_t copy = info->mSize;
1014 + if (copy > numBytesAvailableToWrite) {
1015 + copy = numBytesAvailableToWrite;
1022 + int64_t startTimeUs = ALooper::GetNowUs();
1024 + ssize_t nbytes = state->mAudioTrack->write(
1025 + buffer->base() + info->mOffset, copy);
1027 + CHECK_EQ(nbytes, (ssize_t)copy);
1029 + int64_t delayUs = ALooper::GetNowUs() - startTimeUs;
1031 + uint32_t numFramesWritten = nbytes / state->mAudioTrack->frameSize();
1033 + if (delayUs > 2000ll) {
1034 + ALOGW("AudioTrack::write took %lld us, numFramesAvailableToWrite=%u, "
1035 + "numFramesWritten=%u",
1036 + delayUs, numFramesAvailableToWrite, numFramesWritten);
1039 + info->mOffset += nbytes;
1040 + info->mSize -= nbytes;
1042 + state->mNumFramesWritten += numFramesWritten;
1045 +} // namespace android
1047 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/SimplePlayer.h
1050 + * Copyright (C) 2012 The Android Open Source Project
1052 + * Licensed under the Apache License, Version 2.0 (the "License");
1053 + * you may not use this file except in compliance with the License.
1054 + * You may obtain a copy of the License at
1056 + * http://www.apache.org/licenses/LICENSE-2.0
1058 + * Unless required by applicable law or agreed to in writing, software
1059 + * distributed under the License is distributed on an "AS IS" BASIS,
1060 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1061 + * See the License for the specific language governing permissions and
1062 + * limitations under the License.
1065 +#include <media/stagefright/foundation/AHandler.h>
1066 +#include <media/stagefright/foundation/AString.h>
1067 +#include <utils/KeyedVector.h>
1069 +#include <hybris/media/media_codec_layer.h>
1071 +namespace android {
1076 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
1077 +struct ISurfaceTexture;
1079 +struct IGraphicBufferProducer;
1082 +struct NativeWindowWrapper;
1083 +struct NuMediaExtractor;
1085 +struct SimplePlayer : public AHandler {
1088 + status_t setDataSource(const char *path);
1089 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
1090 + status_t setSurface(const sp<ISurfaceTexture> &surfaceTexture);
1092 + status_t setSurface(const sp<IGraphicBufferProducer> &surfaceTexture);
1094 + status_t prepare();
1100 + virtual ~SimplePlayer();
1102 + virtual void onMessageReceived(const sp<AMessage> &msg);
1113 + kWhatSetDataSource,
1122 + struct BufferInfo {
1126 + int64_t mPresentationTimeUs;
1132 + sp<MediaCodec> mCodec;
1133 + MediaCodecDelegate mCodecDelegate;
1134 + Vector<sp<ABuffer> > mCSD;
1135 + Vector<sp<ABuffer> > mBuffers[2];
1137 + List<size_t> mAvailInputBufferIndices;
1138 + List<BufferInfo> mAvailOutputBufferInfos;
1140 + sp<AudioTrack> mAudioTrack;
1141 + uint32_t mNumFramesWritten;
1146 + sp<NativeWindowWrapper> mNativeWindow;
1148 + sp<NuMediaExtractor> mExtractor;
1149 + sp<ALooper> mCodecLooper;
1150 + KeyedVector<size_t, CodecState> mStateByTrackIndex;
1151 + int32_t mDoMoreStuffGeneration;
1153 + int64_t mStartTimeRealUs;
1155 + status_t onPrepare();
1156 + status_t onStart();
1157 + status_t onStop();
1158 + status_t onReset();
1159 + status_t onDoMoreStuff();
1160 + status_t onOutputFormatChanged(size_t trackIndex, CodecState *state);
1163 + CodecState *state, BufferInfo *info, const sp<ABuffer> &buffer);
1165 + DISALLOW_EVIL_CONSTRUCTORS(SimplePlayer);
1168 +} // namespace android
1170 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/codec.cpp
1173 + * Copyright (C) 2012 The Android Open Source Project
1175 + * Licensed under the Apache License, Version 2.0 (the "License");
1176 + * you may not use this file except in compliance with the License.
1177 + * You may obtain a copy of the License at
1179 + * http://www.apache.org/licenses/LICENSE-2.0
1181 + * Unless required by applicable law or agreed to in writing, software
1182 + * distributed under the License is distributed on an "AS IS" BASIS,
1183 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1184 + * See the License for the specific language governing permissions and
1185 + * limitations under the License.
1188 +#define LOG_NDEBUG 0
1189 +#define LOG_TAG "codec"
1190 +#include <utils/Log.h>
1192 +#include "SimplePlayer.h"
1194 +#include <binder/IServiceManager.h>
1195 +#include <binder/ProcessState.h>
1196 +#include <media/ICrypto.h>
1197 +#include <media/IMediaPlayerService.h>
1198 +#include <media/stagefright/foundation/ABuffer.h>
1199 +#include <media/stagefright/foundation/ADebug.h>
1200 +#include <media/stagefright/foundation/ALooper.h>
1201 +#include <media/stagefright/foundation/AMessage.h>
1202 +#include <media/stagefright/foundation/AString.h>
1203 +#include <media/stagefright/DataSource.h>
1204 +#include <media/stagefright/MediaCodec.h>
1205 +#include <media/stagefright/MediaCodecList.h>
1206 +#include <media/stagefright/MediaDefs.h>
1207 +#include <media/stagefright/NuMediaExtractor.h>
1208 +#include <gui/ISurfaceComposer.h>
1209 +#include <gui/SurfaceComposerClient.h>
1210 +#include <ui/DisplayInfo.h>
1212 +static void usage(const char *me) {
1213 + fprintf(stderr, "usage: %s [-a] use audio\n"
1214 + "\t\t[-v] use video\n"
1215 + "\t\t[-p] playback\n"
1216 + "\t\t[-S] allocate buffers from a surface\n",
1222 +namespace android {
1224 +struct CodecState {
1225 + sp<MediaCodec> mCodec;
1226 + Vector<sp<ABuffer> > mInBuffers;
1227 + Vector<sp<ABuffer> > mOutBuffers;
1228 + bool mSignalledInputEOS;
1229 + bool mSawOutputEOS;
1230 + int64_t mNumBuffersDecoded;
1231 + int64_t mNumBytesDecoded;
1235 +} // namespace android
1238 + const android::sp<android::ALooper> &looper,
1242 + const android::sp<android::Surface> &surface) {
1243 + using namespace android;
1245 + static int64_t kTimeout = 500ll;
1247 + sp<NuMediaExtractor> extractor = new NuMediaExtractor;
1248 + if (extractor->setDataSource(path) != OK) {
1249 + fprintf(stderr, "unable to instantiate extractor.\n");
1253 + KeyedVector<size_t, CodecState> stateByTrack;
1255 + bool haveAudio = false;
1256 + bool haveVideo = false;
1257 + for (size_t i = 0; i < extractor->countTracks(); ++i) {
1258 + sp<AMessage> format;
1259 + status_t err = extractor->getTrackFormat(i, &format);
1260 + CHECK_EQ(err, (status_t)OK);
1263 + CHECK(format->findString("mime", &mime));
1265 + bool isAudio = !strncasecmp(mime.c_str(), "audio/", 6);
1266 + bool isVideo = !strncasecmp(mime.c_str(), "video/", 6);
1268 + if (useAudio && !haveAudio && isAudio) {
1270 + } else if (useVideo && !haveVideo && isVideo) {
1276 + ALOGV("selecting track %d", i);
1278 + err = extractor->selectTrack(i);
1279 + CHECK_EQ(err, (status_t)OK);
1281 + CodecState *state =
1282 + &stateByTrack.editValueAt(stateByTrack.add(i, CodecState()));
1284 + state->mNumBytesDecoded = 0;
1285 + state->mNumBuffersDecoded = 0;
1286 + state->mIsAudio = isAudio;
1288 + state->mCodec = MediaCodec::CreateByType(
1289 + looper, mime.c_str(), false /* encoder */);
1291 + CHECK(state->mCodec != NULL);
1293 + err = state->mCodec->configure(
1294 + format, isVideo ? surface : NULL,
1295 + NULL /* crypto */,
1298 + CHECK_EQ(err, (status_t)OK);
1300 + state->mSignalledInputEOS = false;
1301 + state->mSawOutputEOS = false;
1304 + CHECK(!stateByTrack.isEmpty());
1306 + int64_t startTimeUs = ALooper::GetNowUs();
1308 + for (size_t i = 0; i < stateByTrack.size(); ++i) {
1309 + CodecState *state = &stateByTrack.editValueAt(i);
1311 + sp<MediaCodec> codec = state->mCodec;
1313 + CHECK_EQ((status_t)OK, codec->start());
1315 + CHECK_EQ((status_t)OK, codec->getInputBuffers(&state->mInBuffers));
1316 + CHECK_EQ((status_t)OK, codec->getOutputBuffers(&state->mOutBuffers));
1318 + ALOGV("got %d input and %d output buffers",
1319 + state->mInBuffers.size(), state->mOutBuffers.size());
1322 + bool sawInputEOS = false;
1325 + if (!sawInputEOS) {
1326 + size_t trackIndex;
1327 + status_t err = extractor->getSampleTrackIndex(&trackIndex);
1330 + ALOGV("saw input eos");
1331 + sawInputEOS = true;
1333 + CodecState *state = &stateByTrack.editValueFor(trackIndex);
1336 + err = state->mCodec->dequeueInputBuffer(&index, kTimeout);
1339 + ALOGV("filling input buffer %d", index);
1341 + const sp<ABuffer> &buffer = state->mInBuffers.itemAt(index);
1343 + err = extractor->readSampleData(buffer);
1344 + CHECK_EQ(err, (status_t)OK);
1347 + err = extractor->getSampleTime(&timeUs);
1348 + CHECK_EQ(err, (status_t)OK);
1350 + uint32_t bufferFlags = 0;
1352 + err = state->mCodec->queueInputBuffer(
1359 + CHECK_EQ(err, (status_t)OK);
1361 + extractor->advance();
1363 + CHECK_EQ(err, -EAGAIN);
1367 + for (size_t i = 0; i < stateByTrack.size(); ++i) {
1368 + CodecState *state = &stateByTrack.editValueAt(i);
1370 + if (!state->mSignalledInputEOS) {
1373 + state->mCodec->dequeueInputBuffer(&index, kTimeout);
1376 + ALOGV("signalling input EOS on track %d", i);
1378 + err = state->mCodec->queueInputBuffer(
1383 + MediaCodec::BUFFER_FLAG_EOS);
1385 + CHECK_EQ(err, (status_t)OK);
1387 + state->mSignalledInputEOS = true;
1389 + CHECK_EQ(err, -EAGAIN);
1395 + bool sawOutputEOSOnAllTracks = true;
1396 + for (size_t i = 0; i < stateByTrack.size(); ++i) {
1397 + CodecState *state = &stateByTrack.editValueAt(i);
1398 + if (!state->mSawOutputEOS) {
1399 + sawOutputEOSOnAllTracks = false;
1404 + if (sawOutputEOSOnAllTracks) {
1408 + for (size_t i = 0; i < stateByTrack.size(); ++i) {
1409 + CodecState *state = &stateByTrack.editValueAt(i);
1411 + if (state->mSawOutputEOS) {
1418 + int64_t presentationTimeUs;
1420 + status_t err = state->mCodec->dequeueOutputBuffer(
1421 + &index, &offset, &size, &presentationTimeUs, &flags,
1425 + ALOGV("draining output buffer %d, time = %lld us",
1426 + index, presentationTimeUs);
1428 + ++state->mNumBuffersDecoded;
1429 + state->mNumBytesDecoded += size;
1431 + err = state->mCodec->releaseOutputBuffer(index);
1432 + CHECK_EQ(err, (status_t)OK);
1434 + if (flags & MediaCodec::BUFFER_FLAG_EOS) {
1435 + ALOGV("reached EOS on output.");
1437 + state->mSawOutputEOS = true;
1439 + } else if (err == INFO_OUTPUT_BUFFERS_CHANGED) {
1440 + ALOGV("INFO_OUTPUT_BUFFERS_CHANGED");
1441 + CHECK_EQ((status_t)OK,
1442 + state->mCodec->getOutputBuffers(&state->mOutBuffers));
1444 + ALOGV("got %d output buffers", state->mOutBuffers.size());
1445 + } else if (err == INFO_FORMAT_CHANGED) {
1446 + sp<AMessage> format;
1447 + CHECK_EQ((status_t)OK, state->mCodec->getOutputFormat(&format));
1449 + ALOGV("INFO_FORMAT_CHANGED: %s", format->debugString().c_str());
1451 + CHECK_EQ(err, -EAGAIN);
1456 + int64_t elapsedTimeUs = ALooper::GetNowUs() - startTimeUs;
1458 + for (size_t i = 0; i < stateByTrack.size(); ++i) {
1459 + CodecState *state = &stateByTrack.editValueAt(i);
1461 + CHECK_EQ((status_t)OK, state->mCodec->release());
1463 + if (state->mIsAudio) {
1464 + ALOGD("track %d: %lld bytes received. %.2f KB/sec\n",
1466 + state->mNumBytesDecoded,
1467 + state->mNumBytesDecoded * 1E6 / 1024 / elapsedTimeUs);
1469 + ALOGD("track %d: %lld frames decoded, %.2f fps. %lld bytes "
1470 + "received. %.2f KB/sec\n",
1472 + state->mNumBuffersDecoded,
1473 + state->mNumBuffersDecoded * 1E6 / elapsedTimeUs,
1474 + state->mNumBytesDecoded,
1475 + state->mNumBytesDecoded * 1E6 / 1024 / elapsedTimeUs);
1482 +int main(int argc, char **argv) {
1483 + using namespace android;
1485 + const char *me = argv[0];
1487 + bool useAudio = false;
1488 + bool useVideo = false;
1489 + bool playback = false;
1490 + bool useSurface = false;
1493 + while ((res = getopt(argc, argv, "havpSD")) >= 0) {
1515 + useSurface = true;
1535 + if (!useAudio && !useVideo) {
1536 + useAudio = useVideo = true;
1539 + ProcessState::self()->startThreadPool();
1541 + DataSource::RegisterDefaultSniffers();
1543 + sp<ALooper> looper = new ALooper;
1546 + sp<SurfaceComposerClient> composerClient;
1547 + sp<SurfaceControl> control;
1548 + sp<Surface> surface;
1550 + if (playback || (useSurface && useVideo)) {
1551 + composerClient = new SurfaceComposerClient;
1552 + CHECK_EQ(composerClient->initCheck(), (status_t)OK);
1554 + sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(
1555 + ISurfaceComposer::eDisplayIdMain));
1557 + SurfaceComposerClient::getDisplayInfo(display, &info);
1558 + ssize_t displayWidth = info.w;
1559 + ssize_t displayHeight = info.h;
1561 + ALOGV("display is %ld x %ld\n", displayWidth, displayHeight);
1563 + control = composerClient->createSurface(
1564 + String8("A Surface"),
1567 + PIXEL_FORMAT_RGB_565,
1570 + CHECK(control != NULL);
1571 + CHECK(control->isValid());
1573 + SurfaceComposerClient::openGlobalTransaction();
1574 + CHECK_EQ(control->setLayer(INT_MAX), (status_t)OK);
1575 + CHECK_EQ(control->show(), (status_t)OK);
1576 + SurfaceComposerClient::closeGlobalTransaction();
1578 + surface = control->getSurface();
1579 + CHECK(surface != NULL);
1583 + sp<SimplePlayer> player = new SimplePlayer;
1584 + looper->registerHandler(player);
1586 + player->setDataSource(argv[0]);
1587 + player->setSurface(surface->getSurfaceTexture());
1589 + ALOGD("Playing for 60 seconds\n");
1594 + decode(looper, argv[0], useAudio, useVideo, surface);
1597 + if (playback || (useSurface && useVideo)) {
1598 + composerClient->dispose();
1606 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/direct_media_test.cpp
1609 + * Copyright (C) 2013 Canonical Ltd
1611 + * Licensed under the Apache License, Version 2.0 (the "License");
1612 + * you may not use this file except in compliance with the License.
1613 + * You may obtain a copy of the License at
1615 + * http://www.apache.org/licenses/LICENSE-2.0
1617 + * Unless required by applicable law or agreed to in writing, software
1618 + * distributed under the License is distributed on an "AS IS" BASIS,
1619 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1620 + * See the License for the specific language governing permissions and
1621 + * limitations under the License.
1623 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
1624 + * Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
1627 +#include <hybris/media/media_compatibility_layer.h>
1628 +#include "direct_media_test.h"
1630 +#include <utils/Errors.h>
1632 +#include <hybris/surface_flinger/surface_flinger_compatibility_layer.h>
1634 +#include <GLES2/gl2.h>
1635 +#include <GLES2/gl2ext.h>
1637 +#include <sys/stat.h>
1638 +#include <sys/types.h>
1640 +#include <unistd.h>
1647 +using namespace android;
1649 +static float DestWidth = 0.0, DestHeight = 0.0;
1650 +// Actual video dimmensions
1651 +static int Width = 0, Height = 0;
1653 +static GLfloat positionCoordinates[8];
1655 +MediaPlayerWrapper *player = NULL;
1657 +void calculate_position_coordinates()
1659 + // Assuming cropping output for now
1660 + float x = 1, y = 1;
1663 + x = float(Width / DestWidth);
1664 + y = float(Height / DestHeight);
1666 + // Make the larger side be 1
1675 + positionCoordinates[0] = -x;
1676 + positionCoordinates[1] = y;
1677 + positionCoordinates[2] = -x;
1678 + positionCoordinates[3] = -y;
1679 + positionCoordinates[4] = x;
1680 + positionCoordinates[5] = -y;
1681 + positionCoordinates[6] = x;
1682 + positionCoordinates[7] = y;
1685 +WindowRenderer::WindowRenderer(int width, int height)
1686 + : mThreadCmd(CMD_IDLE)
1688 + createThread(threadStart, this);
1691 +WindowRenderer::~WindowRenderer()
1695 +int WindowRenderer::threadStart(void* self)
1697 + ((WindowRenderer *)self)->glThread();
1701 +void WindowRenderer::glThread()
1703 + printf("%s\n", __PRETTY_FUNCTION__);
1705 + Mutex::Autolock autoLock(mLock);
1708 +struct ClientWithSurface
1711 + SfSurface* surface;
1714 +ClientWithSurface client_with_surface(bool setup_surface_with_egl)
1716 + ClientWithSurface cs = ClientWithSurface();
1718 + cs.client = sf_client_create();
1721 + printf("Problem creating client ... aborting now.");
1725 + static const size_t primary_display = 0;
1727 + DestWidth = sf_get_display_width(primary_display);
1728 + DestHeight = sf_get_display_height(primary_display);
1729 + printf("Primary display width: %f, height: %f\n", DestWidth, DestHeight);
1731 + SfSurfaceCreationParameters params = {
1736 + -1, //PIXEL_FORMAT_RGBA_8888,
1739 + setup_surface_with_egl, // Do not associate surface with egl, will be done by camera HAL
1740 + "MediaCompatLayerTestSurface"
1743 + cs.surface = sf_surface_create(cs.client, ¶ms);
1745 + if (!cs.surface) {
1746 + printf("Problem creating surface ... aborting now.");
1750 + sf_surface_make_current(cs.surface);
1757 + static const char *vertex_shader()
1760 + "attribute vec4 a_position; \n"
1761 + "attribute vec2 a_texCoord; \n"
1762 + "uniform mat4 m_texMatrix; \n"
1763 + "varying vec2 v_texCoord; \n"
1764 + "varying float topDown; \n"
1767 + " gl_Position = a_position; \n"
1768 + " v_texCoord = (m_texMatrix * vec4(a_texCoord, 0.0, 1.0)).xy;\n"
1772 + static const char *fragment_shader()
1775 + "#extension GL_OES_EGL_image_external : require \n"
1776 + "precision mediump float; \n"
1777 + "varying vec2 v_texCoord; \n"
1778 + "uniform samplerExternalOES s_texture; \n"
1781 + " gl_FragColor = texture2D( s_texture, v_texCoord );\n"
1785 + static GLuint loadShader(GLenum shaderType, const char* pSource)
1787 + GLuint shader = glCreateShader(shaderType);
1790 + glShaderSource(shader, 1, &pSource, NULL);
1791 + glCompileShader(shader);
1792 + GLint compiled = 0;
1793 + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
1796 + GLint infoLen = 0;
1797 + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
1799 + char* buf = (char*) malloc(infoLen);
1801 + glGetShaderInfoLog(shader, infoLen, NULL, buf);
1802 + fprintf(stderr, "Could not compile shader %d:\n%s\n",
1806 + glDeleteShader(shader);
1811 + printf("Error, during shader creation: %i\n", glGetError());
1817 + static GLuint create_program(const char* pVertexSource, const char* pFragmentSource)
1819 + GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource);
1820 + if (!vertexShader) {
1821 + printf("vertex shader not compiled\n");
1825 + GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource);
1826 + if (!pixelShader) {
1827 + printf("frag shader not compiled\n");
1831 + GLuint program = glCreateProgram();
1833 + glAttachShader(program, vertexShader);
1834 + glAttachShader(program, pixelShader);
1835 + glLinkProgram(program);
1836 + GLint linkStatus = GL_FALSE;
1837 + glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
1839 + if (linkStatus != GL_TRUE) {
1840 + GLint bufLength = 0;
1841 + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
1843 + char* buf = (char*) malloc(bufLength);
1845 + glGetProgramInfoLog(program, bufLength, NULL, buf);
1846 + fprintf(stderr, "Could not link program:\n%s\n", buf);
1850 + glDeleteProgram(program);
1858 + RenderData() : program_object(create_program(vertex_shader(), fragment_shader()))
1860 + position_loc = glGetAttribLocation(program_object, "a_position");
1861 + tex_coord_loc = glGetAttribLocation(program_object, "a_texCoord");
1862 + sampler_loc = glGetUniformLocation(program_object, "s_texture");
1863 + matrix_loc = glGetUniformLocation(program_object, "m_texMatrix");
1866 + // Handle to a program object
1867 + GLuint program_object;
1868 + // Attribute locations
1869 + GLint position_loc;
1870 + GLint tex_coord_loc;
1871 + // Sampler location
1872 + GLint sampler_loc;
1873 + // Matrix location
1877 +static int setup_video_texture(ClientWithSurface *cs, GLuint *preview_texture_id)
1879 + assert(cs != NULL);
1880 + assert(preview_texture_id != NULL);
1882 + sf_surface_make_current(cs->surface);
1884 + glGenTextures(1, preview_texture_id);
1885 + glClearColor(0, 0, 0, 0);
1886 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1887 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
1888 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1889 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1891 + android_media_set_preview_texture(player, *preview_texture_id);
1896 +static void print_gl_error(unsigned int line)
1898 + GLint error = glGetError();
1899 + printf("GL error: %#04x (line: %d)\n", error, line);
1902 +static int update_gl_buffer(RenderData *render_data, EGLDisplay *disp, EGLSurface *surface)
1904 + assert(disp != NULL);
1905 + assert(surface != NULL);
1907 + GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
1909 + const GLfloat textureCoordinates[] = {
1916 + calculate_position_coordinates();
1918 + glClear(GL_COLOR_BUFFER_BIT);
1919 + // Use the program object
1920 + glUseProgram(render_data->program_object);
1921 + // Enable attributes
1922 + glEnableVertexAttribArray(render_data->position_loc);
1923 + glEnableVertexAttribArray(render_data->tex_coord_loc);
1924 + // Load the vertex position
1925 + glVertexAttribPointer(render_data->position_loc,
1930 + positionCoordinates);
1931 + // Load the texture coordinate
1932 + glVertexAttribPointer(render_data->tex_coord_loc,
1937 + textureCoordinates);
1939 + GLfloat matrix[16];
1940 + android_media_surface_texture_get_transformation_matrix(player, matrix);
1942 + glUniformMatrix4fv(render_data->matrix_loc, 1, GL_FALSE, matrix);
1944 + glActiveTexture(GL_TEXTURE0);
1945 + // Set the sampler texture unit to 0
1946 + glUniform1i(render_data->sampler_loc, 0);
1947 + glUniform1i(render_data->matrix_loc, 0);
1948 + android_media_update_surface_texture(player);
1949 + glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
1950 + //glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
1951 + glDisableVertexAttribArray(render_data->position_loc);
1952 + glDisableVertexAttribArray(render_data->tex_coord_loc);
1954 + eglSwapBuffers(*disp, *surface);
1959 +void set_video_size_cb(int height, int width, void *context)
1961 + printf("Video height: %d, width: %d\n", height, width);
1962 + printf("Video dest height: %f, width: %f\n", DestHeight, DestWidth);
1968 +int main(int argc, char **argv)
1971 + printf("Usage: direct_media_test <video_to_play>\n");
1972 + return EXIT_FAILURE;
1975 + player = android_media_new_player();
1976 + if (player == NULL) {
1977 + printf("Problem creating new media player.\n");
1978 + return EXIT_FAILURE;
1981 + // Set player event cb for when the video size is known:
1982 + android_media_set_video_size_cb(player, set_video_size_cb, NULL);
1984 + printf("Setting data source to: %s.\n", argv[1]);
1986 + if (android_media_set_data_source(player, argv[1]) != OK) {
1987 + printf("Failed to set data source: %s\n", argv[1]);
1988 + return EXIT_FAILURE;
1991 + WindowRenderer renderer(DestWidth, DestHeight);
1993 + printf("Creating EGL surface.\n");
1994 + ClientWithSurface cs = client_with_surface(true /* Associate surface with egl. */);
1995 + if (!cs.surface) {
1996 + printf("Problem acquiring surface for preview");
1997 + return EXIT_FAILURE;
2000 + printf("Creating GL texture.\n");
2001 + GLuint preview_texture_id;
2002 + EGLDisplay disp = sf_client_get_egl_display(cs.client);
2003 + EGLSurface surface = sf_surface_get_egl_surface(cs.surface);
2005 + sf_surface_make_current(cs.surface);
2006 + if (setup_video_texture(&cs, &preview_texture_id) != OK) {
2007 + printf("Problem setting up GL texture for video surface.\n");
2008 + return EXIT_FAILURE;
2011 + RenderData render_data;
2013 + printf("Starting video playback.\n");
2014 + android_media_play(player);
2016 + printf("Updating gl buffer continuously...\n");
2017 + while (android_media_is_playing(player)) {
2018 + update_gl_buffer(&render_data, &disp, &surface);
2021 + android_media_stop(player);
2023 + return EXIT_SUCCESS;
2026 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/direct_media_test.h
2029 + * Copyright (C) 2013 Canonical Ltd
2031 + * Licensed under the Apache License, Version 2.0 (the "License");
2032 + * you may not use this file except in compliance with the License.
2033 + * You may obtain a copy of the License at
2035 + * http://www.apache.org/licenses/LICENSE-2.0
2037 + * Unless required by applicable law or agreed to in writing, software
2038 + * distributed under the License is distributed on an "AS IS" BASIS,
2039 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2040 + * See the License for the specific language governing permissions and
2041 + * limitations under the License.
2043 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
2046 +#ifndef DIRECT_MEDIA_TEST_H_
2047 +#define DIRECT_MEDIA_TEST_H_
2049 +#include <EGL/egl.h>
2050 +#include <GLES2/gl2.h>
2051 +#include <utils/threads.h>
2053 +namespace android {
2057 +class WindowRenderer
2060 + WindowRenderer(int width, int height);
2061 + ~WindowRenderer();
2064 + // The GL thread functions
2065 + static int threadStart(void* self);
2068 + // These variables are used to communicate between the GL thread and
2075 + CMD_RESERVE_TEXTURE,
2076 + CMD_DELETE_TEXTURE,
2080 + RenderInput* mThreadRenderInput;
2081 + GLuint mThreadTextureId;
2087 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_codec_layer.cpp
2090 + * Copyright (C) 2013 Canonical Ltd
2092 + * Licensed under the Apache License, Version 2.0 (the "License");
2093 + * you may not use this file except in compliance with the License.
2094 + * You may obtain a copy of the License at
2096 + * http://www.apache.org/licenses/LICENSE-2.0
2098 + * Unless required by applicable law or agreed to in writing, software
2099 + * distributed under the License is distributed on an "AS IS" BASIS,
2100 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2101 + * See the License for the specific language governing permissions and
2102 + * limitations under the License.
2104 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
2107 +// Uncomment to enable verbose debug output
2108 +#define LOG_NDEBUG 0
2111 +#define LOG_TAG "MediaCodecLayer"
2113 +#include <hybris/media/media_codec_layer.h>
2114 +#include <hybris/media/media_compatibility_layer.h>
2115 +#include <hybris/media/media_format_layer.h>
2117 +#include "media_format_layer_priv.h"
2118 +#include "surface_texture_client_hybris_priv.h"
2121 +#include <sys/stat.h>
2123 +#include <binder/ProcessState.h>
2125 +#include <media/stagefright/foundation/AHandler.h>
2126 +#include <media/stagefright/foundation/AString.h>
2127 +#include <media/ICrypto.h>
2128 +#include <media/stagefright/foundation/ABuffer.h>
2129 +#include <media/stagefright/foundation/ADebug.h>
2130 +#include <media/stagefright/foundation/AMessage.h>
2131 +#include <media/stagefright/MediaCodec.h>
2132 +#include <media/stagefright/MediaErrors.h>
2133 +#include <media/stagefright/NativeWindowWrapper.h>
2135 +#include <utils/Vector.h>
2136 +#include <utils/Log.h>
2137 +#include <utils/RefBase.h>
2139 +#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__);
2141 +using namespace android;
2143 +struct _MediaCodecDelegate : public AHandler
2146 + typedef sp<_MediaCodecDelegate> Ptr;
2148 + explicit _MediaCodecDelegate(void *context);
2149 + virtual ~_MediaCodecDelegate();
2152 + virtual void onMessageReceived(const sp<AMessage> &msg) { }
2155 + sp<MediaCodec> media_codec;
2156 + sp<ALooper> looper;
2158 + Vector<sp<ABuffer> > input_buffers;
2159 + Vector<sp<ABuffer> > output_buffers;
2160 + List<MediaCodecBufferInfo> available_output_buffer_infos;
2161 + List<size_t> available_input_buffer_indices;
2162 + bool output_format_changed;
2163 + bool hardware_rendering;
2166 + unsigned int refcount;
2169 +_MediaCodecDelegate::_MediaCodecDelegate(void *context)
2170 + : output_format_changed(false),
2171 + hardware_rendering(false),
2178 +_MediaCodecDelegate::~_MediaCodecDelegate()
2183 +static inline _MediaCodecDelegate *get_internal_delegate(MediaCodecDelegate delegate)
2185 + if (delegate == NULL)
2187 + ALOGE("delegate must not be NULL");
2191 + _MediaCodecDelegate *d = static_cast<_MediaCodecDelegate*>(delegate);
2192 + // Some simple sanity checks that must be true for a valid MediaCodecDelegate instance
2193 + if (d->media_codec == NULL || d->refcount < 1)
2199 +MediaCodecDelegate media_codec_create_by_codec_name(const char *name)
2205 + ALOGE("name must not be NULL");
2209 + ALOGD("Creating codec '%s'", name);
2211 + ProcessState::self()->startThreadPool();
2213 + _MediaCodecDelegate *d(new _MediaCodecDelegate(NULL));
2214 + d->looper = new ALooper;
2215 + d->looper->start();
2217 + d->media_codec = android::MediaCodec::CreateByComponentName(d->looper, name);
2222 +#ifdef SIMPLE_PLAYER
2223 +MediaCodec* media_codec_get(MediaCodecDelegate delegate)
2227 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2231 + return d->media_codec.get();
2235 +MediaCodecDelegate media_codec_create_by_codec_type(const char *type)
2241 + ALOGE("type must not be NULL");
2245 + ALOGD("Creating codec by type '%s'", type);
2247 + ProcessState::self()->startThreadPool();
2249 + _MediaCodecDelegate *d(new _MediaCodecDelegate(NULL));
2250 + d->looper = new ALooper;
2251 + d->looper->start();
2253 + d->media_codec = android::MediaCodec::CreateByType(d->looper, type, false);
2258 +void media_codec_delegate_destroy(MediaCodecDelegate delegate)
2262 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2265 + ALOGE("d == NULL, cannot destroy MediaCodecDelegate instance");
2269 + ALOGI("Releasing media_codec");
2270 + d->media_codec->release();
2271 + ALOGI("Stopping looper");
2272 + d->looper->stop();
2274 + ALOGI("Setting refcount = 0");
2277 + ALOGI("Deleting the MediaCodecDelegate instance");
2281 +void media_codec_delegate_ref(MediaCodecDelegate delegate)
2285 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2292 +void media_codec_delegate_unref(MediaCodecDelegate delegate)
2296 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2299 + ALOGE("d == NULL, cannot unref MediaCodecDelegate instance");
2303 + if (d->refcount > 1)
2306 + media_codec_delegate_destroy (delegate);
2309 +#ifdef SIMPLE_PLAYER
2310 +int media_codec_configure(MediaCodecDelegate delegate, MediaFormat format, void *nativeWindow, uint32_t flags)
2312 +int media_codec_configure(MediaCodecDelegate delegate, MediaFormat format, SurfaceTextureClientHybris stc, uint32_t flags)
2317 + if (format == NULL)
2319 + ALOGE("format must not be NULL");
2323 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2327 + _MediaFormat *format_priv = static_cast<_MediaFormat*>(format);
2328 +#ifndef SIMPLE_PLAYER
2329 + _SurfaceTextureClientHybris *stch = static_cast<_SurfaceTextureClientHybris*>(stc);
2332 + sp<AMessage> aformat = new AMessage;
2333 + aformat->setString("mime", format_priv->mime.c_str());
2334 + if (format_priv->duration_us > 0)
2335 + aformat->setInt64("durationUs", format_priv->duration_us);
2336 + aformat->setInt32("width", format_priv->width);
2337 + aformat->setInt32("height", format_priv->height);
2338 + if (format_priv->max_input_size > 0)
2339 + aformat->setInt32("max-input-size", format_priv->max_input_size);
2341 + ALOGD("Format: %s", aformat->debugString().c_str());
2343 +#ifdef SIMPLE_PLAYER
2344 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
2345 + sp<SurfaceTextureClient> surfaceTextureClient = static_cast<SurfaceTextureClient*>(nativeWindow);
2347 + sp<Surface> surfaceTextureClient = static_cast<Surface*>(nativeWindow);
2349 + // TODO: Don't just pass NULL for the security when DRM is needed
2350 + d->media_codec->configure(aformat, surfaceTextureClient, NULL, flags);
2352 + ALOGD("SurfaceTextureClientHybris: %p", stch);
2354 + // Make sure we're ready to configure the codec and the Surface/SurfaceTextureClient together
2355 + if (stch != NULL && stch->hardwareRendering() && stch->isReady())
2357 + ALOGD("Doing hardware decoding with hardware rendering");
2358 + // TODO: Don't just pass NULL for the security when DRM is needed
2359 + d->media_codec->configure(aformat, stch, NULL, flags);
2363 + ALOGD("Doing hardware decoding path with software rendering");
2364 + // This scenario is for hardware video decoding, but software rendering, therefore there's
2365 + // no need to pass a valid Surface/SurfaceTextureClient instance to configure()
2366 + d->media_codec->configure(aformat, NULL, NULL, flags);
2374 +int media_codec_set_surface_texture_client(MediaCodecDelegate delegate, SurfaceTextureClientHybris stc)
2378 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2383 + ALOGE("stc must not be NULL");
2387 + _SurfaceTextureClientHybris *stcu = static_cast<_SurfaceTextureClientHybris*>(stc);
2388 + status_t err = native_window_api_connect(stcu, NATIVE_WINDOW_API_MEDIA);
2391 + ALOGE("native_window_api_connect returned an error: %s (%d)", strerror(-err), err);
2398 +int media_codec_queue_csd(MediaCodecDelegate delegate, MediaFormat format)
2402 + if (format == NULL)
2404 + ALOGE("format must not be NULL");
2408 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2409 + _MediaFormat *format_priv = static_cast<_MediaFormat*>(format);
2410 + assert(format_priv->csd != NULL);
2412 + status_t err = OK;
2414 + Vector<sp<ABuffer> > input_bufs[1];
2415 + err = d->media_codec->getInputBuffers(&input_bufs[0]);
2416 + CHECK_EQ(err, static_cast<status_t>(OK));
2418 + for (size_t i=0; i<2; ++i)
2420 + const sp<ABuffer> &srcBuffer = format_priv->csd;
2423 + err = d->media_codec->dequeueInputBuffer(&index, -1ll);
2424 + CHECK_EQ(err, static_cast<status_t>(OK));
2426 + const sp<ABuffer> &dstBuffer = input_bufs[0].itemAt(index);
2428 + CHECK_LE(srcBuffer->size(), dstBuffer->capacity());
2429 + dstBuffer->setRange(0, srcBuffer->size());
2430 + memcpy(dstBuffer->data(), srcBuffer->data(), srcBuffer->size());
2433 + err = d->media_codec->queueInputBuffer(
2436 + dstBuffer->size(),
2438 + MediaCodec::BUFFER_FLAG_CODECCONFIG);
2439 + CHECK_EQ(err, static_cast<status_t>(OK));
2445 +int media_codec_start(MediaCodecDelegate delegate)
2449 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2453 + return d->media_codec->start();
2456 +int media_codec_stop(MediaCodecDelegate delegate)
2460 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2464 + return d->media_codec->stop();
2467 +int media_codec_release(MediaCodecDelegate delegate)
2471 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2475 + return d->media_codec->release();
2478 +int media_codec_flush(MediaCodecDelegate delegate)
2482 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2486 + d->available_output_buffer_infos.clear();
2488 + return d->media_codec->flush();
2491 +size_t media_codec_get_input_buffers_size(MediaCodecDelegate delegate)
2495 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2499 + status_t ret = d->media_codec->getInputBuffers(&d->input_buffers);
2502 + ALOGE("Failed to get input buffers size");
2505 + ALOGD("Got %d input buffers", d->input_buffers.size());
2507 + return d->input_buffers.size();
2510 +uint8_t *media_codec_get_nth_input_buffer(MediaCodecDelegate delegate, size_t n)
2514 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2518 + if (d->input_buffers.size() == 0)
2520 + status_t ret = d->media_codec->getInputBuffers(&d->input_buffers);
2523 + ALOGE("Failed to get input buffers");
2528 + if (n > d->input_buffers.size())
2530 + ALOGE("Failed to get %uth input buffer, n > total buffer size", n);
2534 + return d->input_buffers.itemAt(n).get()->data();
2537 +size_t media_codec_get_nth_input_buffer_capacity(MediaCodecDelegate delegate, size_t n)
2541 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2545 + Vector<sp<ABuffer> > input_buffers;
2546 + status_t ret = d->media_codec->getInputBuffers(&input_buffers);
2549 + ALOGE("Failed to get input buffers");
2553 + if (n > input_buffers.size())
2555 + ALOGE("Failed to get %uth input buffer capacity, n > total buffer size", n);
2559 + return input_buffers[n].get()->capacity();
2562 +size_t media_codec_get_output_buffers_size(MediaCodecDelegate delegate)
2566 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2570 + status_t ret = d->media_codec->getOutputBuffers(&d->output_buffers);
2573 + ALOGE("Failed to get output buffers size");
2576 + ALOGD("Got %d output buffers", d->output_buffers.size());
2578 + return d->output_buffers.size();
2581 +uint8_t *media_codec_get_nth_output_buffer(MediaCodecDelegate delegate, size_t n)
2585 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2589 + status_t ret = d->media_codec->getOutputBuffers(&d->output_buffers);
2592 + ALOGE("Failed to get output buffers");
2596 + if (n > d->output_buffers.size())
2598 + ALOGE("Failed to get %uth output buffer, n > total buffer size", n);
2602 + return d->output_buffers.itemAt(n).get()->data();
2605 +size_t media_codec_get_nth_output_buffer_capacity(MediaCodecDelegate delegate, size_t n)
2609 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2613 + status_t ret = d->media_codec->getOutputBuffers(&d->output_buffers);
2616 + ALOGE("Failed to get output buffers");
2620 + if (n > d->output_buffers.size())
2622 + ALOGE("Failed to get %uth output buffer capacity, n > total buffer size", n);
2626 + return d->output_buffers[n].get()->capacity();
2629 +#define INFO_TRY_AGAIN_LATER -1
2630 +#define INFO_OUTPUT_FORMAT_CHANGED -2
2631 +#define INFO_OUTPUT_BUFFERS_CHANGED -4
2633 +int media_codec_dequeue_output_buffer(MediaCodecDelegate delegate, MediaCodecBufferInfo *info, int64_t timeout_us)
2639 + ALOGE("info must not be NULL");
2643 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2647 + int ret = d->media_codec->dequeueOutputBuffer(&info->index, &info->offset, &info->size, &info->presentation_time_us, &info->flags, timeout_us);
2648 + ALOGD("dequeueOutputBuffer() ret: %d", ret);
2649 + info->render_retries = 0;
2651 + if (ret == -EAGAIN)
2653 + ALOGD("dequeueOutputBuffer returned %d", ret);
2654 + return INFO_TRY_AGAIN_LATER;
2656 + else if (ret & ~INFO_OUTPUT_BUFFERS_CHANGED)
2658 + ALOGD("Output buffers changed (ret: %d)", ret);
2659 + return INFO_OUTPUT_BUFFERS_CHANGED + 1;
2661 + // FIXME: Get rid of the hardcoded -10 and replace with more elegant solution
2662 + else if (ret & ~(INFO_FORMAT_CHANGED - 10))
2664 + ALOGD("Output buffer format changed (ret: %d)", ret);
2665 + d->output_format_changed = true;
2669 + ALOGD("Dequeued output buffer:\n-----------------------");
2670 + ALOGD("index: %u", info->index);
2671 + ALOGD("offset: %d", info->offset);
2672 + ALOGD("size: %d", info->size);
2673 + ALOGD("presentation_time_us: %lld", info->presentation_time_us);
2674 + ALOGD("flags: %d", info->flags);
2676 + // Keep track of the used output buffer info
2677 + d->available_output_buffer_infos.push_back(*info);
2682 +int media_codec_queue_input_buffer(MediaCodecDelegate delegate, const MediaCodecBufferInfo *info)
2688 + ALOGE("info must not be NULL");
2692 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2696 + // Make sure that there is at least one dequeued input buffer available
2697 + if (d->available_input_buffer_indices.empty())
2699 + ALOGE("Input buffer index %d has not been dequeued, cannot queue input buffer", info->index);
2703 + const size_t index = *d->available_input_buffer_indices.begin();
2704 + d->available_input_buffer_indices.erase(d->available_input_buffer_indices.begin());
2706 + ALOGD("info->index: %d", index);
2707 + ALOGD("info->offset: %d", info->offset);
2708 + ALOGD("info->size: %d", info->size);
2709 + ALOGD("info->presentation_time_us: %lld", info->presentation_time_us);
2710 + ALOGD("info->flags: %d", info->flags);
2713 + status_t ret = d->media_codec->queueInputBuffer(index, info->offset, info->size,
2714 + info->presentation_time_us, info->flags, &err_msg);
2717 + ALOGE("Failed to queue input buffer (err: %d, index: %d)", ret, index);
2718 + ALOGE("Detailed error message: %s", err_msg.c_str());
2724 +int media_codec_dequeue_input_buffer(MediaCodecDelegate delegate, size_t *index, int64_t timeout_us)
2728 + if (index == NULL)
2730 + ALOGE("index must not be NULL");
2734 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2738 + status_t ret = d->media_codec->dequeueInputBuffer(index, timeout_us);
2739 + if (ret == -EAGAIN)
2741 + ALOGD("dequeueInputBuffer returned %d, tried timeout: %d", ret, timeout_us);
2742 + return INFO_TRY_AGAIN_LATER;
2744 + else if (ret == OK)
2746 + ALOGD("Dequeued input buffer (index: %d)", *index);
2747 + d->available_input_buffer_indices.push_back(*index);
2750 + ALOGE("Failed to dequeue input buffer (err: %d, index: %d)", ret, *index);
2755 +int media_codec_release_output_buffer(MediaCodecDelegate delegate, size_t index, uint8_t render)
2758 + ALOGV("Requesting to release output buffer index: %d, render: %d", index, render);
2760 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2764 + status_t ret = OK;
2766 + auto it = d->available_output_buffer_infos.begin();
2767 + while (it != d->available_output_buffer_infos.end())
2769 + MediaCodecBufferInfo *info = &*it;
2770 + ALOGD("info index: %d", info->index);
2771 + ALOGD("info render_retries: %u", info->render_retries);
2772 + if (info->render_retries == 1)
2774 + ALOGV("Rendering and releasing output buffer %d from the available indices list", info->index);
2775 + ret = d->media_codec->renderOutputBufferAndRelease(info->index);
2778 + ALOGE("Failed to release output buffer (ret: %d, index: %d)", ret, info->index);
2779 + ++info->render_retries;
2783 + ALOGV("Successfully rendered output buffer %d on a second try.", info->index);
2784 + d->available_output_buffer_infos.erase(it);
2787 + else if (info->render_retries > 1)
2789 + ALOGV("Tried to render output buffer %d twice, dropping.", info->index);
2790 + ret = d->media_codec->releaseOutputBuffer(info->index);
2791 + d->available_output_buffer_infos.erase(d->available_output_buffer_infos.begin());
2797 + MediaCodecBufferInfo *info = &*d->available_output_buffer_infos.begin();
2798 + // Either render and release the output buffer, or just release.
2801 + ALOGV("Rendering and releasing output buffer %d from the available indices list", info->index);
2802 + ret = d->media_codec->renderOutputBufferAndRelease(info->index);
2806 + ALOGV("Releasing output buffer %d from the available indices list", info->index);
2807 + ret = d->media_codec->releaseOutputBuffer(info->index);
2811 + ALOGE("Failed to release output buffer (ret: %d, index: %d)", ret, info->index);
2812 + ++info->render_retries;
2814 + ALOGV("Released output buffer %d from the available buffer infos list", info->index);
2815 + d->available_output_buffer_infos.erase(d->available_output_buffer_infos.begin());
2821 +MediaFormat media_codec_get_output_format(MediaCodecDelegate delegate)
2825 + _MediaCodecDelegate *d = get_internal_delegate(delegate);
2829 + _MediaFormat *f = new _MediaFormat();
2831 + sp<AMessage> msg_format;
2832 + status_t ret = d->media_codec->getOutputFormat(&msg_format);
2835 + ALOGE("Failed to get the output format");
2839 + ALOGD("Output format: %s", msg_format->debugString().c_str());
2841 + CHECK(msg_format->findString("mime", &f->mime));
2842 + CHECK(msg_format->findInt32("width", &f->width));
2843 + CHECK(msg_format->findInt32("height", &f->height));
2844 + CHECK(msg_format->findInt32("stride", &f->stride));
2845 + CHECK(msg_format->findInt32("slice-height", &f->slice_height));
2846 + CHECK(msg_format->findInt32("color-format", &f->color_format));
2848 + CHECK(msg_format->findRect("crop", &crop.left, &crop.top, &crop.right, &crop.bottom));
2853 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_codec_list.cpp
2856 + * Copyright (C) 2013 Canonical Ltd
2858 + * Licensed under the Apache License, Version 2.0 (the "License");
2859 + * you may not use this file except in compliance with the License.
2860 + * You may obtain a copy of the License at
2862 + * http://www.apache.org/licenses/LICENSE-2.0
2864 + * Unless required by applicable law or agreed to in writing, software
2865 + * distributed under the License is distributed on an "AS IS" BASIS,
2866 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
2867 + * See the License for the specific language governing permissions and
2868 + * limitations under the License.
2870 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
2873 +// Uncomment to enable verbose debug output
2874 +#define LOG_NDEBUG 0
2877 +#define LOG_TAG "MediaCodecList"
2879 +#include <hybris/media/media_codec_list.h>
2881 +#include <media/stagefright/foundation/AString.h>
2882 +#include <media/stagefright/MediaCodecList.h>
2884 +#include <utils/Log.h>
2885 +#include <utils/Vector.h>
2887 +#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__);
2889 +using namespace android;
2891 +ssize_t media_codec_list_find_codec_by_type(const char *type, bool encoder, size_t startIndex)
2894 + return MediaCodecList::getInstance()->findCodecByType(type, encoder, startIndex);
2897 +ssize_t media_codec_list_find_codec_by_name(const char *name)
2900 + return MediaCodecList::getInstance()->findCodecByName(name);
2903 +size_t media_codec_list_count_codecs()
2906 + return MediaCodecList::getInstance()->countCodecs();
2909 +void media_codec_list_get_codec_info_at_id(size_t index)
2914 +const char *media_codec_list_get_codec_name(size_t index)
2917 + return MediaCodecList::getInstance()->getCodecName(index);
2920 +bool media_codec_list_is_encoder(size_t index)
2923 + return MediaCodecList::getInstance()->isEncoder(index);
2926 +size_t media_codec_list_get_num_supported_types(size_t index)
2930 + Vector<AString> types;
2931 + status_t err = MediaCodecList::getInstance()->getSupportedTypes(index, &types);
2934 + ALOGE("Failed to get the number of supported codec types (err: %d)", err);
2937 + ALOGD("Number of supported codec types: %d", types.size());
2939 + return types.size();
2942 +size_t media_codec_list_get_nth_supported_type_len(size_t index, size_t n)
2946 + Vector<AString> types;
2947 + status_t err = MediaCodecList::getInstance()->getSupportedTypes(index, &types);
2949 + return types[n].size();
2952 +int media_codec_list_get_nth_supported_type(size_t index, char *type, size_t n)
2958 + ALOGE("types must not be NULL");
2962 + Vector<AString> types;
2963 + status_t err = MediaCodecList::getInstance()->getSupportedTypes(index, &types);
2964 + for (size_t i=0; i<types[n].size(); ++i)
2965 + type[i] = types.itemAt(n).c_str()[i];
2970 +static void media_codec_list_get_num_codec_capabilities(size_t index, const char *type, size_t *num_profile_levels, size_t *num_color_formats)
2974 + Vector<MediaCodecList::ProfileLevel> profile_levels;
2975 + Vector<uint32_t> color_formats;
2976 + ALOGD("index: %d, type: '%s'", index, type);
2977 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
2978 + status_t err = MediaCodecList::getInstance()->getCodecCapabilities(index, type, &profile_levels, &color_formats);
2981 + status_t err = MediaCodecList::getInstance()->getCodecCapabilities(index, type, &profile_levels, &color_formats, &flags);
2985 + ALOGE("Failed to get the number of supported codec capabilities (err: %d)", err);
2989 + if (num_profile_levels != NULL)
2991 + ALOGD("Number of codec profile levels: %d", profile_levels.size());
2992 + *num_profile_levels = profile_levels.size();
2994 + if (num_color_formats != NULL)
2996 + ALOGD("Number of codec color formats: %d", color_formats.size());
2997 + *num_color_formats = color_formats.size();
3001 +size_t media_codec_list_get_num_profile_levels(size_t index, const char *type)
3006 + media_codec_list_get_num_codec_capabilities(index, type, &num, NULL);
3011 +size_t media_codec_list_get_num_color_formats(size_t index, const char *type)
3016 + media_codec_list_get_num_codec_capabilities(index, type, NULL, &num);
3021 +int media_codec_list_get_nth_codec_profile_level(size_t index, const char *type, profile_level *pro_level, size_t n)
3027 + ALOGE("types must not be NULL");
3031 + if (pro_level == NULL)
3033 + ALOGE("pro_level must not be NULL");
3037 + Vector<MediaCodecList::ProfileLevel> profile_levels;
3038 + Vector<uint32_t> formats;
3039 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
3040 + status_t err = MediaCodecList::getInstance()->getCodecCapabilities(index, type, &profile_levels, &formats);
3043 + status_t err = MediaCodecList::getInstance()->getCodecCapabilities(index, type, &profile_levels, &formats, &flags);
3047 + ALOGE("Failed to get the nth codec profile level (err: %d)", err);
3051 + pro_level->profile = profile_levels[n].mProfile;
3052 + pro_level->level = profile_levels[n].mLevel;
3057 +int media_codec_list_get_codec_color_formats(size_t index, const char *type, uint32_t *color_formats)
3061 + Vector<MediaCodecList::ProfileLevel> profile_levels;
3062 + Vector<uint32_t> formats;
3063 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
3064 + status_t err = MediaCodecList::getInstance()->getCodecCapabilities(index, type, &profile_levels, &formats);
3067 + status_t err = MediaCodecList::getInstance()->getCodecCapabilities(index, type, &profile_levels, &formats, &flags);
3071 + ALOGE("Failed to get the number of supported codec types (err: %d)", err);
3075 + for (size_t i=0; i<formats.size(); ++i)
3077 + color_formats[i] = formats[i];
3078 + ALOGD("Color format [%d]: %d", i, formats[i]);
3084 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_compatibility_layer.cpp
3087 + * Copyright (C) 2013 Canonical Ltd
3089 + * Licensed under the Apache License, Version 2.0 (the "License");
3090 + * you may not use this file except in compliance with the License.
3091 + * You may obtain a copy of the License at
3093 + * http://www.apache.org/licenses/LICENSE-2.0
3095 + * Unless required by applicable law or agreed to in writing, software
3096 + * distributed under the License is distributed on an "AS IS" BASIS,
3097 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3098 + * See the License for the specific language governing permissions and
3099 + * limitations under the License.
3101 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
3102 + * Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
3105 +// Uncomment to enable verbose debug output
3106 +#define LOG_NDEBUG 0
3109 +#define LOG_TAG "MediaCompatibilityLayer"
3111 +#include <hybris/media/media_compatibility_layer.h>
3114 +#include <sys/stat.h>
3116 +#include <media/mediaplayer.h>
3118 +#include <binder/ProcessState.h>
3119 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
3120 +#include <gui/SurfaceTexture.h>
3122 +#include <gui/GLConsumer.h>
3125 +#include <GLES2/gl2.h>
3126 +#include <GLES2/gl2ext.h>
3128 +#include <ui/GraphicBuffer.h>
3130 +#include <utils/Log.h>
3132 +#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
3136 +NativeBufferAlloc::NativeBufferAlloc() {
3139 +NativeBufferAlloc::~NativeBufferAlloc() {
3142 +sp<GraphicBuffer> NativeBufferAlloc::createGraphicBuffer(uint32_t w, uint32_t h,
3143 + PixelFormat format, uint32_t usage, status_t* error) {
3144 + sp<GraphicBuffer> graphicBuffer(new GraphicBuffer(w, h, format, usage));
3145 + status_t err = graphicBuffer->initCheck();
3147 + if (err != 0 || graphicBuffer->handle == 0) {
3148 + if (err == NO_MEMORY) {
3149 + GraphicBuffer::dumpAllocationsToSystemLog();
3151 + ALOGI("GraphicBufferAlloc::createGraphicBuffer(w=%d, h=%d) "
3152 + "failed (%s), handle=%p",
3153 + w, h, strerror(-err), graphicBuffer->handle);
3156 + return graphicBuffer;
3159 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
3160 +struct FrameAvailableListener : public android::SurfaceTexture::FrameAvailableListener
3162 +struct FrameAvailableListener : public android::GLConsumer::FrameAvailableListener
3166 + FrameAvailableListener()
3167 + : set_video_texture_needs_update_cb(NULL),
3168 + video_texture_needs_update_context(NULL)
3172 + // From android::GLConsumer/SurfaceTexture::FrameAvailableListener
3173 + void onFrameAvailable()
3175 + if (set_video_texture_needs_update_cb != NULL)
3176 + set_video_texture_needs_update_cb(video_texture_needs_update_context);
3179 + void setVideoTextureNeedsUpdateCb(on_video_texture_needs_update cb, void *context)
3181 + set_video_texture_needs_update_cb = cb;
3182 + video_texture_needs_update_context = context;
3186 + on_video_texture_needs_update set_video_texture_needs_update_cb;
3187 + void *video_texture_needs_update_context;
3190 +class MediaPlayerListenerWrapper : public android::MediaPlayerListener
3193 + MediaPlayerListenerWrapper()
3194 + : set_video_size_cb(NULL),
3195 + video_size_context(NULL),
3197 + error_context(NULL),
3198 + playback_complete_cb(NULL),
3199 + playback_complete_context(NULL),
3200 + media_prepared_cb(NULL),
3201 + media_prepared_context(NULL)
3205 + void notify(int msg, int ext1, int ext2, const android::Parcel *obj)
3207 + ALOGV("\tmsg: %d, ext1: %d, ext2: %d \n", msg, ext1, ext2);
3210 + case android::MEDIA_PREPARED:
3211 + ALOGV("\tMEDIA_PREPARED msg\n");
3212 + if (media_prepared_cb != NULL)
3213 + media_prepared_cb(media_prepared_context);
3215 + ALOGW("Failed to signal media prepared, callback not set.");
3217 + case android::MEDIA_PLAYBACK_COMPLETE:
3218 + ALOGV("\tMEDIA_PLAYBACK_COMPLETE msg\n");
3219 + if (playback_complete_cb != NULL)
3220 + playback_complete_cb(playback_complete_context);
3222 + ALOGW("Failed to signal end of playback, callback not set.");
3224 + case android::MEDIA_BUFFERING_UPDATE:
3225 + ALOGV("\tMEDIA_BUFFERING_UPDATE msg\n");
3227 + case android::MEDIA_SEEK_COMPLETE:
3228 + ALOGV("\tMEDIA_SEEK_COMPLETE msg\n");
3230 + case android::MEDIA_SET_VIDEO_SIZE:
3231 + ALOGV("\tMEDIA_SET_VIDEO_SIZE msg\n");
3232 + if (set_video_size_cb != NULL)
3233 + set_video_size_cb(ext2, ext1, video_size_context);
3235 + ALOGE("Failed to set video size. set_video_size_cb is NULL.");
3237 + case android::MEDIA_TIMED_TEXT:
3238 + ALOGV("\tMEDIA_TIMED_TEXT msg\n");
3240 + case android::MEDIA_ERROR:
3241 + ALOGV("\tMEDIA_ERROR msg\n");
3242 + // TODO: Extend this cb to include the error message
3243 + if (error_cb != NULL)
3244 + error_cb(error_context);
3246 + ALOGE("Failed to signal error to app layer, callback not set.");
3248 + case android::MEDIA_INFO:
3249 + ALOGV("\tMEDIA_INFO msg\n");
3252 + ALOGV("\tUnknown media msg\n");
3256 + void setVideoSizeCb(on_msg_set_video_size cb, void *context)
3258 + REPORT_FUNCTION();
3260 + set_video_size_cb = cb;
3261 + video_size_context = context;
3264 + void setErrorCb(on_msg_error cb, void *context)
3266 + REPORT_FUNCTION();
3269 + error_context = context;
3272 + void setPlaybackCompleteCb(on_playback_complete cb, void *context)
3274 + REPORT_FUNCTION();
3276 + playback_complete_cb = cb;
3277 + playback_complete_context = context;
3280 + void setMediaPreparedCb(on_media_prepared cb, void *context)
3282 + REPORT_FUNCTION();
3284 + media_prepared_cb = cb;
3285 + media_prepared_context = context;
3289 + on_msg_set_video_size set_video_size_cb;
3290 + void *video_size_context;
3291 + on_msg_error error_cb;
3292 + void *error_context;
3293 + on_playback_complete playback_complete_cb;
3294 + void *playback_complete_context;
3295 + on_media_prepared media_prepared_cb;
3296 + void *media_prepared_context;
3299 +// ----- MediaPlayer Wrapper ----- //
3301 +struct MediaPlayerWrapper : public android::MediaPlayer
3304 + MediaPlayerWrapper()
3307 + media_player_listener(new MediaPlayerListenerWrapper()),
3308 + frame_listener(new FrameAvailableListener),
3309 + left_volume(1), // Set vol to 100% for this track by default
3313 + setListener(media_player_listener);
3314 + // Update the live volume with the cached values
3315 + MediaPlayer::setVolume(left_volume, right_volume);
3318 + ~MediaPlayerWrapper()
3324 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
3325 + android::status_t setVideoSurfaceTexture(const android::sp<android::SurfaceTexture> &surfaceTexture)
3327 + android::status_t setVideoSurfaceTexture(android::sp<android::BufferQueue> bq, const android::sp<android::GLConsumer> &surfaceTexture)
3330 + REPORT_FUNCTION();
3332 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
3333 + surfaceTexture->getBufferQueue()->setBufferCount(5);
3335 + bq->setBufferCount(5);
3337 + texture = surfaceTexture;
3338 + texture->setFrameAvailableListener(frame_listener);
3340 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
3341 + return MediaPlayer::setVideoSurfaceTexture(surfaceTexture->getBufferQueue());
3343 + return MediaPlayer::setVideoSurfaceTexture(bq);
3347 + void updateGLConsumer()
3349 + assert(texture != NULL);
3350 + texture->updateTexImage();
3353 + void get_transformation_matrix_for_surface_texture(GLfloat* matrix)
3355 + assert(texture != NULL);
3356 + texture->getTransformMatrix(matrix);
3359 + void setVideoSizeCb(on_msg_set_video_size cb, void *context)
3361 + REPORT_FUNCTION();
3363 + assert(media_player_listener != NULL);
3364 + media_player_listener->setVideoSizeCb(cb, context);
3367 + void setVideoTextureNeedsUpdateCb(on_video_texture_needs_update cb, void *context)
3369 + REPORT_FUNCTION();
3371 + assert(frame_listener != NULL);
3372 + frame_listener->setVideoTextureNeedsUpdateCb(cb, context);
3375 + void setErrorCb(on_msg_error cb, void *context)
3377 + REPORT_FUNCTION();
3379 + assert(media_player_listener != NULL);
3380 + media_player_listener->setErrorCb(cb, context);
3383 + void setPlaybackCompleteCb(on_playback_complete cb, void *context)
3385 + REPORT_FUNCTION();
3387 + assert(media_player_listener != NULL);
3388 + media_player_listener->setPlaybackCompleteCb(cb, context);
3391 + void setMediaPreparedCb(on_media_prepared cb, void *context)
3393 + REPORT_FUNCTION();
3395 + assert(media_player_listener != NULL);
3396 + media_player_listener->setMediaPreparedCb(cb, context);
3399 + void getVolume(float *leftVolume, float *rightVolume)
3401 + *leftVolume = left_volume;
3402 + *rightVolume = right_volume;
3405 + android::status_t setVolume(float leftVolume, float rightVolume)
3407 + REPORT_FUNCTION();
3409 + left_volume = leftVolume;
3410 + right_volume = rightVolume;
3411 + return MediaPlayer::setVolume(leftVolume, rightVolume);
3414 + int getSourceFd() const { return source_fd; }
3415 + void setSourceFd(int fd) { source_fd = fd; }
3418 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
3419 + android::sp<android::SurfaceTexture> texture;
3421 + android::sp<android::GLConsumer> texture;
3423 + android::sp<MediaPlayerListenerWrapper> media_player_listener;
3424 + android::sp<FrameAvailableListener> frame_listener;
3425 + float left_volume;
3426 + float right_volume;
3428 +}; // MediaPlayerWrapper
3430 +using namespace android;
3432 +// ----- Media Player C API Implementation ----- //
3434 +void android_media_set_video_size_cb(MediaPlayerWrapper *mp, on_msg_set_video_size cb, void *context)
3436 + REPORT_FUNCTION();
3439 + ALOGE("mp must not be NULL");
3443 + mp->setVideoSizeCb(cb, context);
3446 +void android_media_set_video_texture_needs_update_cb(MediaPlayerWrapper *mp, on_video_texture_needs_update cb, void *context)
3448 + REPORT_FUNCTION();
3451 + ALOGE("mp must not be NULL");
3455 + mp->setVideoTextureNeedsUpdateCb(cb, context);
3458 +void android_media_set_error_cb(MediaPlayerWrapper *mp, on_msg_error cb, void *context)
3460 + REPORT_FUNCTION();
3463 + ALOGE("mp must not be NULL");
3467 + mp->setErrorCb(cb, context);
3470 +void android_media_set_playback_complete_cb(MediaPlayerWrapper *mp, on_playback_complete cb, void *context)
3472 + REPORT_FUNCTION();
3475 + ALOGE("mp must not be NULL");
3479 + mp->setPlaybackCompleteCb(cb, context);
3482 +void android_media_set_media_prepared_cb(MediaPlayerWrapper *mp, on_media_prepared cb, void *context)
3484 + REPORT_FUNCTION();
3487 + ALOGE("mp must not be NULL");
3491 + mp->setMediaPreparedCb(cb, context);
3494 +MediaPlayerWrapper *android_media_new_player()
3496 + REPORT_FUNCTION();
3498 + MediaPlayerWrapper *mp = new MediaPlayerWrapper();
3500 + ALOGE("Failed to create new MediaPlayerWrapper instance.");
3504 + // Required for internal player state processing. Without this, prepare() and start() hang.
3505 + ProcessState::self()->startThreadPool();
3510 +int android_media_set_data_source(MediaPlayerWrapper *mp, const char* url)
3512 + REPORT_FUNCTION();
3515 + ALOGE("mp must not be NULL");
3519 + if (url == NULL) {
3520 + ALOGE("url must not be NULL");
3524 + ALOGD("url: %s", url);
3526 + String16 src(url);
3527 + if (src.startsWith(String16("http://")) == true) {
3528 + ALOGD("HTTP source URL detected");
3529 + mp->setDataSource(url, NULL);
3531 + ALOGD("File source URL detected");
3532 + int fd = open(url, O_RDONLY);
3535 + ALOGE("Failed to open source data at: %s\n", url);
3539 + mp->setSourceFd(fd);
3544 + ALOGD("source file length: %lld\n", st.st_size);
3546 + mp->setDataSource(fd, 0, st.st_size);
3553 +int android_media_set_preview_texture(MediaPlayerWrapper *mp, int texture_id)
3555 + REPORT_FUNCTION();
3558 + ALOGE("mp must not be NULL");
3562 + android::sp<android::NativeBufferAlloc> native_alloc(
3563 + new android::NativeBufferAlloc()
3566 + android::sp<android::BufferQueue> buffer_queue(
3567 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
3568 + new android::BufferQueue(false, NULL, native_alloc)
3570 + new android::BufferQueue(NULL, native_alloc)
3574 + static const bool allow_synchronous_mode = true;
3575 + // Create a new GLConsumer/SurfaceTexture from the texture_id in synchronous mode (don't wait on all data in the buffer)
3576 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
3577 + mp->setVideoSurfaceTexture(android::sp<android::SurfaceTexture>(
3578 + new android::SurfaceTexture(
3580 + mp->setVideoSurfaceTexture(buffer_queue, android::sp<android::GLConsumer>(
3581 + new android::GLConsumer(
3583 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
3585 + allow_synchronous_mode,
3586 + GL_TEXTURE_EXTERNAL_OES,
3592 + GL_TEXTURE_EXTERNAL_OES,
3600 +void android_media_update_surface_texture(MediaPlayerWrapper *mp)
3603 + ALOGE("mp must not be NULL");
3607 + mp->updateGLConsumer();
3610 +void android_media_surface_texture_get_transformation_matrix(MediaPlayerWrapper *mp, GLfloat* matrix)
3613 + ALOGE("mp must not be NULL");
3617 + mp->get_transformation_matrix_for_surface_texture(matrix);
3620 +int android_media_play(MediaPlayerWrapper *mp)
3622 + REPORT_FUNCTION();
3625 + ALOGE("mp must not be NULL");
3630 + const char *tmp = mp->isPlaying() ? "yes" : "no";
3631 + ALOGV("Is playing?: %s\n", tmp);
3636 +int android_media_pause(MediaPlayerWrapper *mp)
3638 + REPORT_FUNCTION();
3641 + ALOGE("mp must not be NULL");
3650 +int android_media_stop(MediaPlayerWrapper *mp)
3652 + REPORT_FUNCTION();
3655 + ALOGE("mp must not be NULL");
3661 + int fd = mp->getSourceFd();
3668 +bool android_media_is_playing(MediaPlayerWrapper *mp)
3671 + if (mp->isPlaying())
3678 +int android_media_seek_to(MediaPlayerWrapper *mp, int msec)
3680 + REPORT_FUNCTION();
3683 + ALOGE("mp must not be NULL");
3687 + return mp->seekTo(msec);
3690 +int android_media_get_current_position(MediaPlayerWrapper *mp, int *msec)
3693 + ALOGE("mp must not be NULL");
3697 + return mp->getCurrentPosition(msec);
3700 +int android_media_get_duration(MediaPlayerWrapper *mp, int *msec)
3702 + REPORT_FUNCTION();
3705 + ALOGE("mp must not be NULL");
3709 + return mp->getDuration(msec);
3712 +int android_media_get_volume(MediaPlayerWrapper *mp, int *volume)
3714 + REPORT_FUNCTION();
3716 + if (volume == NULL) {
3717 + ALOGE("volume must not be NULL");
3722 + ALOGE("mp must not be NULL");
3726 + float left_volume = 0, right_volume = 0;
3727 + mp->getVolume(&left_volume, &right_volume);
3728 + *volume = left_volume * 100;
3733 +int android_media_set_volume(MediaPlayerWrapper *mp, int volume)
3735 + REPORT_FUNCTION();
3738 + ALOGE("mp must not be NULL");
3742 + float left_volume = float(volume / 100);
3743 + float right_volume = float(volume / 100);
3744 + return mp->setVolume(left_volume, right_volume);
3747 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_format_layer.cpp
3750 + * Copyright (C) 2013 Canonical Ltd
3752 + * Licensed under the Apache License, Version 2.0 (the "License");
3753 + * you may not use this file except in compliance with the License.
3754 + * You may obtain a copy of the License at
3756 + * http://www.apache.org/licenses/LICENSE-2.0
3758 + * Unless required by applicable law or agreed to in writing, software
3759 + * distributed under the License is distributed on an "AS IS" BASIS,
3760 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
3761 + * See the License for the specific language governing permissions and
3762 + * limitations under the License.
3764 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
3767 +// Uncomment to enable verbose debug output
3768 +#define LOG_NDEBUG 0
3771 +#define LOG_TAG "MediaFormatLayer"
3773 +#include <hybris/media/media_format_layer.h>
3774 +#include "media_format_layer_priv.h"
3776 +#include <assert.h>
3778 +#include <utils/Log.h>
3780 +#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__);
3782 +using namespace android;
3784 +static inline _MediaFormat *get_internal_format(MediaFormat format)
3786 + if (format == NULL)
3788 + ALOGE("format must not be NULL");
3792 + _MediaFormat *mf = static_cast<_MediaFormat*>(format);
3793 + assert(mf->refcount >= 1);
3798 +MediaFormat media_format_create_video_format(const char *mime, int32_t width, int32_t height, int64_t duration_us, int32_t max_input_size)
3802 + _MediaFormat *format = new _MediaFormat();
3803 + format->mime = AString(mime);
3804 + format->width = width;
3805 + format->height = height;
3806 + format->duration_us = duration_us;
3807 + format->max_input_size = max_input_size;
3812 +void media_format_destroy(MediaFormat format)
3816 + _MediaFormat *mf = get_internal_format(format);
3826 +void media_format_ref(MediaFormat format)
3830 + _MediaFormat *mf = get_internal_format(format);
3837 +void media_format_unref(MediaFormat format)
3841 + _MediaFormat *mf = get_internal_format(format);
3849 +void media_format_set_byte_buffer(MediaFormat format, const char *key, uint8_t *data, size_t size)
3853 + _MediaFormat *mf = get_internal_format(format);
3856 + if (key == NULL || data == NULL || size == 0)
3859 + mf->csd_key_name = AString(key);
3860 + mf->csd = sp<ABuffer>(new ABuffer(data, size));
3863 +const char* media_format_get_mime(MediaFormat format)
3867 + _MediaFormat *mf = get_internal_format(format);
3871 + return mf->mime.c_str();
3874 +int64_t media_format_get_duration_us(MediaFormat format)
3878 + _MediaFormat *mf = get_internal_format(format);
3882 + return mf->duration_us;
3885 +int32_t media_format_get_width(MediaFormat format)
3889 + _MediaFormat *mf = get_internal_format(format);
3896 +int32_t media_format_get_height(MediaFormat format)
3900 + _MediaFormat *mf = get_internal_format(format);
3904 + return mf->height;
3907 +int32_t media_format_get_max_input_size(MediaFormat format)
3911 + _MediaFormat *mf = get_internal_format(format);
3915 + return mf->max_input_size;
3918 +int32_t media_format_get_stride(MediaFormat format)
3922 + _MediaFormat *mf = get_internal_format(format);
3926 + return mf->stride;
3929 +int32_t media_format_get_slice_height(MediaFormat format)
3933 + _MediaFormat *mf = get_internal_format(format);
3937 + return mf->height;
3940 +int32_t media_format_get_color_format(MediaFormat format)
3944 + _MediaFormat *mf = get_internal_format(format);
3948 + return mf->color_format;
3951 +int32_t media_format_get_crop_left(MediaFormat format)
3955 + _MediaFormat *mf = get_internal_format(format);
3959 + return mf->crop_left;
3962 +int32_t media_format_get_crop_right(MediaFormat format)
3966 + _MediaFormat *mf = get_internal_format(format);
3970 + return mf->crop_right;
3973 +int32_t media_format_get_crop_top(MediaFormat format)
3977 + _MediaFormat *mf = get_internal_format(format);
3981 + return mf->crop_top;
3984 +int32_t media_format_get_crop_bottom(MediaFormat format)
3988 + _MediaFormat *mf = get_internal_format(format);
3992 + return mf->crop_bottom;
3995 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_format_layer_priv.cpp
3998 + * Copyright (C) 2013 Canonical Ltd
4000 + * Licensed under the Apache License, Version 2.0 (the "License");
4001 + * you may not use this file except in compliance with the License.
4002 + * You may obtain a copy of the License at
4004 + * http://www.apache.org/licenses/LICENSE-2.0
4006 + * Unless required by applicable law or agreed to in writing, software
4007 + * distributed under the License is distributed on an "AS IS" BASIS,
4008 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4009 + * See the License for the specific language governing permissions and
4010 + * limitations under the License.
4012 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
4015 +#include <stddef.h>
4016 +#include <unistd.h>
4018 +#include <media/stagefright/foundation/AString.h>
4020 +#include <utils/RefBase.h>
4026 +struct _MediaFormat : public RefBase
4034 + int64_t duration_us;
4037 + int32_t max_input_size;
4039 + unsigned int refcount;
4048 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/media_format_layer_priv.h
4051 + * Copyright (C) 2013 Canonical Ltd
4053 + * Licensed under the Apache License, Version 2.0 (the "License");
4054 + * you may not use this file except in compliance with the License.
4055 + * You may obtain a copy of the License at
4057 + * http://www.apache.org/licenses/LICENSE-2.0
4059 + * Unless required by applicable law or agreed to in writing, software
4060 + * distributed under the License is distributed on an "AS IS" BASIS,
4061 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4062 + * See the License for the specific language governing permissions and
4063 + * limitations under the License.
4065 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
4068 +#ifndef MEDIA_FORMAT_LAYER_PRIV_H_
4069 +#define MEDIA_FORMAT_LAYER_PRIV_H_
4071 +#include <stddef.h>
4072 +#include <unistd.h>
4074 +#include <media/stagefright/foundation/AString.h>
4075 +#include <media/stagefright/foundation/ABuffer.h>
4077 +#include <utils/RefBase.h>
4079 +struct _MediaFormat : public android::RefBase
4085 + max_input_size(0),
4098 + android::AString mime;
4099 + int64_t duration_us;
4102 + int32_t max_input_size;
4103 + android::AString csd_key_name;
4104 + android::sp<android::ABuffer> csd;
4107 + int32_t slice_height;
4108 + int32_t color_format;
4109 + int32_t crop_left;
4110 + int32_t crop_right;
4112 + int32_t crop_bottom;
4114 + unsigned int refcount;
4117 +#endif // MEDIA_FORMAT_LAYER_PRIV_H_
4119 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/recorder_compatibility_layer.cpp
4122 + * Copyright (C) 2013 Canonical Ltd
4124 + * Licensed under the Apache License, Version 2.0 (the "License");
4125 + * you may not use this file except in compliance with the License.
4126 + * You may obtain a copy of the License at
4128 + * http://www.apache.org/licenses/LICENSE-2.0
4130 + * Unless required by applicable law or agreed to in writing, software
4131 + * distributed under the License is distributed on an "AS IS" BASIS,
4132 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4133 + * See the License for the specific language governing permissions and
4134 + * limitations under the License.
4136 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
4137 + * Guenter Schwann <guenter.schwann@canonical.com>
4138 + * Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
4141 +#include <hybris/internal/camera_control.h>
4142 +#include <hybris/media/recorder_compatibility_layer.h>
4144 +#include <camera/Camera.h>
4145 +#include <camera/ICamera.h>
4146 +#include <media/mediarecorder.h>
4148 +//#define LOG_NDEBUG 0
4150 +#define LOG_TAG "MediaRecorderCompatibilityLayer"
4151 +#include <utils/KeyedVector.h>
4152 +#include <utils/Log.h>
4154 +#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__)
4157 + * \brief The MediaRecorderListenerWrapper class is used to listen to events
4158 + * from the MediaRecorder
4160 +class MediaRecorderListenerWrapper : public android::MediaRecorderListener
4163 + MediaRecorderListenerWrapper()
4165 + error_context(NULL)
4169 + void notify(int msg, int ext1, int ext2)
4171 + ALOGV("\tmsg: %d, ext1: %d, ext2: %d \n", msg, ext1, ext2);
4174 + case android::MEDIA_RECORDER_EVENT_ERROR:
4175 + ALOGV("\tMEDIA_RECORDER_EVENT_ERROR msg\n");
4176 + // TODO: Extend this cb to include the error message
4177 + if (error_cb != NULL)
4178 + error_cb(error_context);
4180 + ALOGE("Failed to signal error to app layer, callback not set.");
4183 + ALOGV("\tUnknown notification\n");
4187 + void setErrorCb(on_recorder_msg_error cb, void *context)
4189 + REPORT_FUNCTION();
4191 + error_context = context;
4195 + on_recorder_msg_error error_cb;
4196 + void *error_context;
4200 + * \brief The MediaRecorderWrapper struct wraps the MediaRecorder class
4202 +struct MediaRecorderWrapper : public android::MediaRecorder
4205 + MediaRecorderWrapper()
4206 + : MediaRecorder(),
4207 + media_recorder_listener(new MediaRecorderListenerWrapper())
4209 + setListener(media_recorder_listener);
4212 + ~MediaRecorderWrapper()
4217 + void setErrorCb(on_recorder_msg_error cb, void *context)
4219 + REPORT_FUNCTION();
4221 + assert(media_recorder_listener != NULL);
4222 + media_recorder_listener->setErrorCb(cb, context);
4226 + android::sp<MediaRecorderListenerWrapper> media_recorder_listener;
4230 +using namespace android;
4233 + * \brief android_recorder_set_error_cb
4234 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4235 + * \param cb The callback function to be called when a recording error occurs
4238 +void android_recorder_set_error_cb(MediaRecorderWrapper *mr, on_recorder_msg_error cb,
4241 + REPORT_FUNCTION();
4244 + ALOGE("mr must not be NULL");
4248 + mr->setErrorCb(cb, context);
4252 + * \brief android_media_new_recorder creates a new MediaRecorder
4253 + * \return New MediaRecorder object, or NULL if the object could not be created.
4255 +MediaRecorderWrapper *android_media_new_recorder()
4257 + REPORT_FUNCTION();
4259 + MediaRecorderWrapper *mr = new MediaRecorderWrapper;
4261 + ALOGE("Failed to create new MediaRecorderWrapper instance.");
4269 + * \brief android_recorder_initCheck
4270 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4271 + * \return negative value if an error occured
4273 +int android_recorder_initCheck(MediaRecorderWrapper *mr)
4275 + REPORT_FUNCTION();
4278 + ALOGE("mr must not be NULL");
4282 + return mr->initCheck();
4286 + * \brief android_recorder_setCamera sets the camera object for recording videos
4288 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4289 + * \param control Wrapper for the camera (see camera in hybris)
4290 + * \return negative value if an error occured
4292 +int android_recorder_setCamera(MediaRecorderWrapper *mr, CameraControl* control)
4294 + REPORT_FUNCTION();
4297 + ALOGE("mr must not be NULL");
4300 + if (control == NULL) {
4301 + ALOGE("control must not be NULL");
4305 + return mr->setCamera(control->camera->remote(), control->camera->getRecordingProxy());
4309 + * \brief android_recorder_setVideoSource sets the video source.
4310 + * If no video source is set, only audio is recorded.
4311 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4312 + * \param vs The video source. It's either the camera of gralloc buffer
4313 + * \return negative value if an error occured
4315 +int android_recorder_setVideoSource(MediaRecorderWrapper *mr, VideoSource vs)
4317 + REPORT_FUNCTION();
4320 + ALOGE("mr must not be NULL");
4324 + return mr->setVideoSource(static_cast<int>(vs));
4328 + * \brief android_recorder_setAudioSource
4329 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4330 + * \param as The audio source.
4331 + * \return negative value if an error occured
4333 +int android_recorder_setAudioSource(MediaRecorderWrapper *mr, AudioSource as)
4335 + REPORT_FUNCTION();
4338 + ALOGE("mr must not be NULL");
4342 + return mr->setAudioSource(static_cast<int>(as));
4346 + * \brief android_recorder_setOutputFormat
4347 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4348 + * \param of The output file format
4349 + * \return negative value if an error occured
4351 +int android_recorder_setOutputFormat(MediaRecorderWrapper *mr, OutputFormat of)
4353 + REPORT_FUNCTION();
4356 + ALOGE("mr must not be NULL");
4360 + return mr->setOutputFormat(static_cast<int>(of));
4364 + * \brief android_recorder_setVideoEncoder
4365 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4366 + * \param ve The video encoder sets the codec for the video
4367 + * \return negative value if an error occured
4369 +int android_recorder_setVideoEncoder(MediaRecorderWrapper *mr, VideoEncoder ve)
4371 + REPORT_FUNCTION();
4374 + ALOGE("mr must not be NULL");
4378 + return mr->setVideoEncoder(static_cast<int>(ve));
4382 + * \brief android_recorder_setAudioEncoder
4383 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4384 + * \param ae The audio encoder sets the codec for the audio
4385 + * \return negative value if an error occured
4387 +int android_recorder_setAudioEncoder(MediaRecorderWrapper *mr, AudioEncoder ae)
4389 + REPORT_FUNCTION();
4392 + ALOGE("mr must not be NULL");
4396 + return mr->setAudioEncoder(static_cast<int>(ae));
4400 + * \brief android_recorder_setOutputFile sets the output file to the given file descriptor
4401 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4402 + * \param fd File descriptor of an open file, that the stream can be written to
4403 + * \return negative value if an error occured
4405 +int android_recorder_setOutputFile(MediaRecorderWrapper *mr, int fd)
4407 + REPORT_FUNCTION();
4410 + ALOGE("mr must not be NULL");
4414 + return mr->setOutputFile(fd, 0, 0);
4418 + * \brief android_recorder_setVideoSize
4419 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4420 + * \param width width for the video to record
4421 + * \param height height for the video to record
4422 + * \return negative value if an error occured
4424 +int android_recorder_setVideoSize(MediaRecorderWrapper *mr, int width, int height)
4426 + REPORT_FUNCTION();
4429 + ALOGE("mr must not be NULL");
4433 + return mr->setVideoSize(width, height);
4437 + * \brief android_recorder_setVideoFrameRate
4438 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4439 + * \param frames_per_second Frames per second has typical values for a movie clip in 720p is 30
4440 + * \return negative value if an error occured
4442 +int android_recorder_setVideoFrameRate(MediaRecorderWrapper *mr, int frames_per_second)
4444 + REPORT_FUNCTION();
4447 + ALOGE("mr must not be NULL");
4451 + return mr->setVideoFrameRate(frames_per_second);
4455 + * \brief android_recorder_setParameters sets a parameter. Even those without
4456 + * explicit function.
4457 + * For possible parameters look for example in StagefrightRecorder::setParameter()
4458 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4459 + * \param parameters list of parameters. format is "parameter1=value;parameter2=value"
4460 + * \return negative value if an error occured
4462 +int android_recorder_setParameters(MediaRecorderWrapper *mr, const char* parameters)
4464 + REPORT_FUNCTION();
4467 + ALOGE("mr must not be NULL");
4471 + String8 params(parameters);
4472 + return mr->setParameters(params);
4476 + * \brief android_recorder_start starts the recording.
4477 + * The MediaRecorder has to be in state "prepared"
4478 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4479 + * \return negative value if an error occured
4481 +int android_recorder_start(MediaRecorderWrapper *mr)
4483 + REPORT_FUNCTION();
4486 + ALOGE("mr must not be NULL");
4490 + return mr->start();
4494 + * \brief android_recorder_stop Stops a running recording.
4495 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4496 + * \return negative value if an error occured
4498 +int android_recorder_stop(MediaRecorderWrapper *mr)
4500 + REPORT_FUNCTION();
4503 + ALOGE("mr must not be NULL");
4507 + return mr->stop();
4511 + * \brief android_recorder_prepare put the MediaRecorder into state "prepare"
4512 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4513 + * \return negative value if an error occured
4515 +int android_recorder_prepare(MediaRecorderWrapper *mr)
4517 + REPORT_FUNCTION();
4520 + ALOGE("mr must not be NULL");
4524 + return mr->prepare();
4528 + * \brief android_recorder_reset resets the MediaRecorder
4529 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4530 + * \return negative value if an error occured
4532 +int android_recorder_reset(MediaRecorderWrapper *mr)
4534 + REPORT_FUNCTION();
4537 + ALOGE("mr must not be NULL");
4541 + return mr->reset();
4545 + * \brief android_recorder_close closes the MediaRecorder
4546 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4547 + * \return negative value if an error occured
4549 +int android_recorder_close(MediaRecorderWrapper *mr)
4551 + REPORT_FUNCTION();
4554 + ALOGE("mr must not be NULL");
4558 + return mr->close();
4562 + * \brief android_recorder_release releases the MediaRecorder resources
4563 + * This deletes the object. So don't use it after calling this function.
4564 + * \param mr A MediaRecorderWrapper instance, created by calling android_media_new_recorder()
4565 + * \return negative value if an error occured
4567 +int android_recorder_release(MediaRecorderWrapper *mr)
4569 + REPORT_FUNCTION();
4572 + ALOGE("mr must not be NULL");
4576 + return mr->release();
4579 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/surface_texture_client_hybris.cpp
4582 + * Copyright (C) 2013 Canonical Ltd
4584 + * Licensed under the Apache License, Version 2.0 (the "License");
4585 + * you may not use this file except in compliance with the License.
4586 + * You may obtain a copy of the License at
4588 + * http://www.apache.org/licenses/LICENSE-2.0
4590 + * Unless required by applicable law or agreed to in writing, software
4591 + * distributed under the License is distributed on an "AS IS" BASIS,
4592 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4593 + * See the License for the specific language governing permissions and
4594 + * limitations under the License.
4596 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
4599 +// Uncomment to enable verbose debug output
4600 +#define LOG_NDEBUG 0
4603 +#define LOG_TAG "SurfaceTextureClientHybris"
4605 +#include <hybris/media/surface_texture_client_hybris.h>
4606 +#include "surface_texture_client_hybris_priv.h"
4608 +#include <ui/GraphicBuffer.h>
4609 +#include <utils/Log.h>
4610 +#include <ui/Region.h>
4611 +#include <gui/Surface.h>
4612 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4613 +#include <gui/SurfaceTextureClient.h>
4616 +#include <GLES2/gl2.h>
4617 +#include <GLES2/gl2ext.h>
4619 +#define REPORT_FUNCTION() ALOGV("%s \n", __PRETTY_FUNCTION__);
4621 +using namespace android;
4623 +// ----- Begin _SurfaceTextureClientHybris API ----- //
4625 +static inline _SurfaceTextureClientHybris *get_internal_stch(SurfaceTextureClientHybris stc, const char * func)
4629 + ALOGE("stc must not be NULL (%s)", func);
4633 + _SurfaceTextureClientHybris *s = static_cast<_SurfaceTextureClientHybris*>(stc);
4634 + assert(s->refcount >= 1);
4639 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4640 +_SurfaceTextureClientHybris::_SurfaceTextureClientHybris()
4648 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR>=4
4649 +_SurfaceTextureClientHybris::_SurfaceTextureClientHybris(const sp<BufferQueue> &bq)
4650 + : Surface::Surface(bq, true),
4658 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4659 +_SurfaceTextureClientHybris::_SurfaceTextureClientHybris(const _SurfaceTextureClientHybris &stch)
4660 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4661 + : SurfaceTextureClient::SurfaceTextureClient(),
4663 + : Surface::Surface(new BufferQueue(), true),
4665 + refcount(stch.refcount),
4671 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4672 +_SurfaceTextureClientHybris::_SurfaceTextureClientHybris(const sp<ISurfaceTexture> &st)
4673 + : SurfaceTextureClient::SurfaceTextureClient(st),
4675 +_SurfaceTextureClientHybris::_SurfaceTextureClientHybris(const sp<IGraphicBufferProducer> &st)
4676 + : Surface::Surface(st, true),
4685 +_SurfaceTextureClientHybris::~_SurfaceTextureClientHybris()
4692 +bool _SurfaceTextureClientHybris::isReady() const
4697 +int _SurfaceTextureClientHybris::dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd)
4699 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4700 + return SurfaceTextureClient::dequeueBuffer(buffer, fenceFd);
4702 + return Surface::dequeueBuffer(buffer, fenceFd);
4706 +int _SurfaceTextureClientHybris::queueBuffer(ANativeWindowBuffer* buffer, int fenceFd)
4708 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4709 + return SurfaceTextureClient::queueBuffer(buffer, fenceFd);
4711 + return Surface::queueBuffer(buffer, fenceFd);
4715 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4716 +void _SurfaceTextureClientHybris::setISurfaceTexture(const sp<ISurfaceTexture>& surface_texture)
4718 + SurfaceTextureClient::setISurfaceTexture(surface_texture);
4720 +void _SurfaceTextureClientHybris::setISurfaceTexture(const sp<IGraphicBufferProducer>& surface_texture)
4722 + // We don't need to set up the IGraphicBufferProducer as stc needs it when created
4725 + // Ready for rendering
4729 +void _SurfaceTextureClientHybris::setHardwareRendering(bool do_hardware_rendering)
4731 + hardware_rendering = do_hardware_rendering;
4734 +bool _SurfaceTextureClientHybris::hardwareRendering()
4736 + return hardware_rendering;
4739 +// ----- End _SurfaceTextureClientHybris API ----- //
4741 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4742 +static inline void set_surface(_SurfaceTextureClientHybris *stch, const sp<SurfaceTexture> &surface_texture)
4744 +static inline void set_surface(_SurfaceTextureClientHybris *stch, const sp<GLConsumer> &surface_texture)
4752 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4753 + stch->setISurfaceTexture(surface_texture->getBufferQueue());
4755 + stch->setISurfaceTexture(stch->getIGraphicBufferProducer());
4759 +SurfaceTextureClientHybris surface_texture_client_create_by_id(unsigned int texture_id)
4763 + if (texture_id == 0)
4765 + ALOGE("Cannot create new SurfaceTextureClientHybris, texture id must be > 0.");
4769 + // Use a new native buffer allocator vs the default one, which means it'll use the proper one
4770 + // that will allow rendering to work with Mir
4771 + sp<NativeBufferAlloc> native_alloc(new NativeBufferAlloc());
4773 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
4774 + sp<BufferQueue> buffer_queue(new BufferQueue(false, NULL, native_alloc));
4775 + _SurfaceTextureClientHybris *stch(new _SurfaceTextureClientHybris);
4777 + sp<BufferQueue> buffer_queue(new BufferQueue(NULL, native_alloc));
4778 + _SurfaceTextureClientHybris *stch(new _SurfaceTextureClientHybris(buffer_queue));
4781 + ALOGD("stch: %p (%s)", stch, __PRETTY_FUNCTION__);
4783 + if (stch->surface_texture != NULL)
4784 + stch->surface_texture.clear();
4786 + const bool allow_synchronous_mode = true;
4787 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4788 + stch->surface_texture = new SurfaceTexture(texture_id, allow_synchronous_mode, GL_TEXTURE_EXTERNAL_OES, true, buffer_queue);
4789 + set_surface(stch, stch->surface_texture);
4791 + stch->surface_texture = new GLConsumer(buffer_queue, texture_id, GL_TEXTURE_EXTERNAL_OES, true, true);
4793 + set_surface(stch, stch->surface_texture);
4798 +uint8_t surface_texture_client_is_ready_for_rendering(SurfaceTextureClientHybris stc)
4802 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4806 + return static_cast<uint8_t>(s->isReady());
4809 +uint8_t surface_texture_client_hardware_rendering(SurfaceTextureClientHybris stc)
4813 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4817 + return s->hardwareRendering();
4820 +void surface_texture_client_set_hardware_rendering(SurfaceTextureClientHybris stc, uint8_t hardware_rendering)
4824 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4828 + s->setHardwareRendering(static_cast<bool>(hardware_rendering));
4831 +void surface_texture_client_get_transformation_matrix(SurfaceTextureClientHybris stc, float *matrix)
4833 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4837 + s->surface_texture->getTransformMatrix(static_cast<GLfloat*>(matrix));
4840 +void surface_texture_client_update_texture(SurfaceTextureClientHybris stc)
4844 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4848 + s->surface_texture->updateTexImage();
4851 +void surface_texture_client_destroy(SurfaceTextureClientHybris stc)
4855 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4858 + ALOGE("s == NULL, cannot destroy SurfaceTextureClientHybris instance");
4867 +void surface_texture_client_ref(SurfaceTextureClientHybris stc)
4871 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4878 +void surface_texture_client_unref(SurfaceTextureClientHybris stc)
4882 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4885 + ALOGE("s == NULL, cannot unref SurfaceTextureClientHybris instance");
4889 + if (s->refcount > 1)
4892 + surface_texture_client_destroy (stc);
4895 +void surface_texture_client_set_surface_texture(SurfaceTextureClientHybris stc, EGLNativeWindowType native_window)
4897 + _SurfaceTextureClientHybris *s = get_internal_stch(stc, __PRETTY_FUNCTION__);
4901 + if (native_window == NULL)
4903 + ALOGE("native_window must not be NULL");
4907 + sp<Surface> surface = static_cast<Surface*>(native_window);
4908 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4909 + s->setISurfaceTexture(surface->getSurfaceTexture());
4911 + s->setISurfaceTexture(surface->getIGraphicBufferProducer());
4915 +++ libhybris-0.1.0+git20131207+e452e83/compat/media/surface_texture_client_hybris_priv.h
4918 + * Copyright (C) 2013 Canonical Ltd
4920 + * Licensed under the Apache License, Version 2.0 (the "License");
4921 + * you may not use this file except in compliance with the License.
4922 + * You may obtain a copy of the License at
4924 + * http://www.apache.org/licenses/LICENSE-2.0
4926 + * Unless required by applicable law or agreed to in writing, software
4927 + * distributed under the License is distributed on an "AS IS" BASIS,
4928 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4929 + * See the License for the specific language governing permissions and
4930 + * limitations under the License.
4932 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
4935 +#include <gui/Surface.h>
4936 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4937 +#include <gui/SurfaceTextureClient.h>
4939 +#include <gui/GLConsumer.h>
4942 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4943 +struct _SurfaceTextureClientHybris : public android::SurfaceTextureClient
4945 +struct _SurfaceTextureClientHybris : public android::Surface
4948 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4949 + _SurfaceTextureClientHybris();
4951 + _SurfaceTextureClientHybris(const _SurfaceTextureClientHybris &stch);
4952 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4953 + _SurfaceTextureClientHybris(const android::sp<android::ISurfaceTexture> &st);
4955 + _SurfaceTextureClientHybris(const android::sp<android::BufferQueue> &bq);
4957 + ~_SurfaceTextureClientHybris();
4959 + /** Has a texture id or EGLNativeWindowType been passed in, meaning rendering will function? **/
4960 + bool isReady() const;
4963 + int dequeueBuffer(ANativeWindowBuffer** buffer, int* fenceFd);
4964 + int queueBuffer(ANativeWindowBuffer* buffer, int fenceFd);
4965 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4966 + void setISurfaceTexture(const android::sp<android::ISurfaceTexture>& surface_texture);
4968 + void setISurfaceTexture(const android::sp<android::IGraphicBufferProducer>& surface_texture);
4970 + void setHardwareRendering(bool do_hardware_rendering);
4971 + bool hardwareRendering();
4973 + unsigned int refcount;
4974 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
4975 + android::sp<android::SurfaceTexture> surface_texture;
4977 + android::sp<android::GLConsumer> surface_texture;
4982 + bool hardware_rendering;
4985 --- libhybris-0.1.0+git20131207+e452e83.orig/compat/ui/Android.mk
4986 +++ libhybris-0.1.0+git20131207+e452e83/compat/ui/Android.mk
4988 LOCAL_PATH:= $(call my-dir)
4989 include $(CLEAR_VARS)
4990 +include $(LOCAL_PATH)/../Android.common.mk
4992 HYBRIS_PATH := $(LOCAL_PATH)/../../hybris
4994 --- libhybris-0.1.0+git20131207+e452e83.orig/compat/ui/ui_compatibility_layer.cpp
4995 +++ libhybris-0.1.0+git20131207+e452e83/compat/ui/ui_compatibility_layer.cpp
4996 @@ -126,6 +126,7 @@ void* graphic_buffer_get_native_buffer(s
4997 return buffer->self->getNativeBuffer();
5000 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
5001 void graphic_buffer_set_index(struct graphic_buffer *buffer, int index)
5003 return buffer->self->setIndex(index);
5004 @@ -135,6 +136,7 @@ int graphic_buffer_get_index(struct grap
5006 return buffer->self->getIndex();
5010 int graphic_buffer_init_check(struct graphic_buffer *buffer)
5012 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/Makefile.am
5013 +++ libhybris-0.1.0+git20131207+e452e83/hybris/Makefile.am
5014 @@ -4,7 +4,7 @@ if HAS_ANDROID_4_2_0
5018 -SUBDIRS += egl glesv1 glesv2 ui sf input camera
5019 +SUBDIRS += egl glesv1 glesv2 ui sf input camera media
5020 if HAS_LIBNFC_NXP_HEADERS
5021 SUBDIRS += libnfc_nxp libnfc_ndef_nxp
5023 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/common/hooks.c
5024 +++ libhybris-0.1.0+git20131207+e452e83/hybris/common/hooks.c
5026 #include <stdio_ext.h>
5029 +#include <limits.h>
5032 #include <strings.h>
5034 #include <sys/ipc.h>
5035 #include <sys/shm.h>
5037 +#include <linux/futex.h>
5038 +#include <sys/syscall.h>
5039 +#include <sys/time.h>
5044 @@ -64,8 +69,12 @@ static int locale_inited = 0;
5046 #define ANDROID_MUTEX_SHARED_MASK 0x2000
5047 #define ANDROID_COND_SHARED_MASK 0x0001
5048 +#define ANDROID_COND_COUNTER_INCREMENT 0x0002
5049 +#define ANDROID_COND_COUNTER_MASK (~ANDROID_COND_SHARED_MASK)
5050 #define ANDROID_RWLOCKATTR_SHARED_MASK 0x0010
5052 +#define ANDROID_COND_IS_SHARED(c) (((c)->value & ANDROID_COND_SHARED_MASK) != 0)
5054 /* For the static initializer types */
5055 #define ANDROID_PTHREAD_MUTEX_INITIALIZER 0
5056 #define ANDROID_PTHREAD_RECURSIVE_MUTEX_INITIALIZER 0x4000
5057 @@ -87,6 +96,11 @@ struct _hook {
5061 +/* pthread cond struct as done in Android */
5063 + int volatile value;
5067 static int hybris_check_android_shared_mutex(unsigned int mutex_addr)
5069 @@ -109,9 +123,59 @@ static int hybris_check_android_shared_c
5070 (cond_addr & ANDROID_COND_SHARED_MASK))
5073 + /* In case android is setting up cond_addr with a negative value,
5074 + * used for error control */
5075 + if (cond_addr > HYBRIS_SHM_MASK_TOP)
5081 +/* Based on Android's Bionic pthread implementation.
5082 + * This is just needed when we have a shared cond with Android */
5083 +static int __android_pthread_cond_pulse(android_cond_t *cond, int counter)
5091 + flags = (cond->value & ~ANDROID_COND_COUNTER_MASK);
5093 + long oldval = cond->value;
5095 + /* In our case all we need to do is make sure the negative value
5096 + * is under our range, which is the last 0xF from SHM_MASK */
5098 + newval = ((oldval + ANDROID_COND_COUNTER_INCREMENT) &
5099 + ANDROID_COND_COUNTER_MASK) | flags;
5101 + newval = ((oldval - ANDROID_COND_COUNTER_INCREMENT) &
5102 + ANDROID_COND_COUNTER_MASK) | flags;
5103 + if (__sync_bool_compare_and_swap(&cond->value, oldval, newval))
5107 + int pshared = cond->value & ANDROID_COND_SHARED_MASK;
5108 + fret = syscall(SYS_futex , &cond->value,
5109 + pshared ? FUTEX_WAKE : FUTEX_WAKE_PRIVATE, counter,
5110 + NULL, NULL, NULL);
5111 + LOGD("futex based pthread_cond_*, value %d, counter %d, ret %d",
5112 + cond->value, counter, fret);
5116 +int android_pthread_cond_broadcast(android_cond_t *cond)
5118 + return __android_pthread_cond_pulse(cond, INT_MAX);
5121 +int android_pthread_cond_signal(android_cond_t *cond)
5123 + return __android_pthread_cond_pulse(cond, 1);
5126 static void hybris_set_mutex_attr(unsigned int android_value, pthread_mutexattr_t *attr)
5128 /* Init already sets as PTHREAD_MUTEX_NORMAL */
5129 @@ -577,8 +641,8 @@ static int my_pthread_cond_broadcast(pth
5131 unsigned int value = (*(unsigned int *) cond);
5132 if (hybris_check_android_shared_cond(value)) {
5133 - LOGD("shared condition with Android, not broadcasting.");
5135 + LOGD("Shared condition with Android, broadcasting with futex.");
5136 + return android_pthread_cond_broadcast((android_cond_t *) cond);
5139 pthread_cond_t *realcond = (pthread_cond_t *) value;
5140 @@ -598,8 +662,8 @@ static int my_pthread_cond_signal(pthrea
5141 unsigned int value = (*(unsigned int *) cond);
5143 if (hybris_check_android_shared_cond(value)) {
5144 - LOGD("Shared condition with Android, not signaling.");
5146 + LOGD("Shared condition with Android, broadcasting with futex.");
5147 + return android_pthread_cond_signal((android_cond_t *) cond);
5150 pthread_cond_t *realcond = (pthread_cond_t *) value;
5151 @@ -1217,6 +1281,56 @@ FP_ATTRIB static double my_strtod(const
5152 return strtod_l(nptr, endptr, hybris_locale);
5155 +static int __my_system_property_read(const void *pi, char *name, char *value)
5157 + return property_get(name, value, NULL);
5160 +static int __my_system_property_get(const char *name, char *value)
5162 + return property_get(name, value, NULL);
5165 +static int __my_system_property_foreach(void (*propfn)(const void *pi, void *cookie), void *cookie)
5170 +static const void *__my_system_property_find(const char *name)
5175 +static unsigned int __my_system_property_serial(const void *pi)
5180 +static int __my_system_property_wait(const void *pi)
5185 +static int __my_system_property_update(void *pi, const char *value, unsigned int len)
5190 +static int __my_system_property_add(const char *name, unsigned int namelen, const char *value, unsigned int valuelen)
5195 +static unsigned int __my_system_property_wait_any(unsigned int serial)
5200 +static const void *__my_system_property_find_nth(unsigned n)
5205 extern int __cxa_atexit(void (*)(void*), void*, void*);
5207 static struct _hook hooks[] = {
5208 @@ -1449,6 +1563,17 @@ static struct _hook hooks[] = {
5210 {"getgrgid", getgrgid},
5211 {"__cxa_atexit", __cxa_atexit},
5212 + {"__system_property_read", __my_system_property_read},
5213 + {"__system_property_get", __my_system_property_get},
5214 + {"__system_property_set", property_set},
5215 + {"__system_property_foreach", __my_system_property_foreach},
5216 + {"__system_property_find", __my_system_property_find},
5217 + {"__system_property_serial", __my_system_property_serial},
5218 + {"__system_property_wait", __my_system_property_wait},
5219 + {"__system_property_update", __my_system_property_update},
5220 + {"__system_property_add", __my_system_property_add},
5221 + {"__system_property_wait_any", __my_system_property_wait_any},
5222 + {"__system_property_find_nth", __my_system_property_find_nth},
5226 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/common/hooks_shm.c
5227 +++ libhybris-0.1.0+git20131207+e452e83/hybris/common/hooks_shm.c
5228 @@ -123,7 +123,9 @@ static void _hybris_shm_init()
5230 LOGD("Creating a new shared memory segment.");
5232 - _hybris_shm_fd = shm_open(HYBRIS_SHM_PATH, O_RDWR | O_CREAT, 0660);
5233 + mode_t pumask = umask(0);
5234 + _hybris_shm_fd = shm_open(HYBRIS_SHM_PATH, O_RDWR | O_CREAT, 0666);
5236 if (_hybris_shm_fd >= 0) {
5237 ftruncate( _hybris_shm_fd, size_to_map );
5238 /* Map the memory object */
5239 @@ -171,11 +173,12 @@ static void _hybris_shm_extend_region()
5242 * Determine if the pointer that has been extracted by hybris is
5243 - * pointing to an address in the shared memory
5244 + * pointing to an address in the shared memory.
5246 int hybris_is_pointer_in_shm(void *ptr)
5248 - if ((unsigned int)ptr >= HYBRIS_SHM_MASK)
5249 + if (((unsigned int) ptr >= HYBRIS_SHM_MASK) &&
5250 + ((unsigned int) ptr <= HYBRIS_SHM_MASK_TOP))
5254 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/common/hooks_shm.h
5255 +++ libhybris-0.1.0+git20131207+e452e83/hybris/common/hooks_shm.h
5260 +/* Leave space to workaround the issue that Android might pass negative int values */
5261 +#define HYBRIS_SHM_MASK_TOP 0xFFFFFFF0UL
5263 typedef unsigned int hybris_shm_pointer_t;
5266 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/common/jb/dlfcn.c
5267 +++ libhybris-0.1.0+git20131207+e452e83/hybris/common/jb/dlfcn.c
5268 @@ -78,7 +78,7 @@ const char *android_dlerror(void)
5269 void *android_dlsym(void *handle, const char *symbol)
5276 pthread_mutex_lock(&dl_lock);
5277 @@ -142,7 +142,7 @@ int android_dladdr(const void *addr, Dl_
5278 info->dli_fbase = (void*)si->base;
5280 /* Determine if any symbol in the library contains the specified address */
5281 - Elf32_Sym *sym = find_containing_symbol(addr, si);
5282 + Elf_Sym *sym = find_containing_symbol(addr, si);
5285 info->dli_sname = si->strtab + sym->st_name;
5286 @@ -192,7 +192,7 @@ int android_dl_iterate_phdr(int (*cb)(st
5290 -static Elf32_Sym libdl_symtab[] = {
5291 +static Elf_Sym libdl_symtab[] = {
5292 // total length of libdl_info.strtab, including trailing 0
5293 // This is actually the the STH_UNDEF entry. Technically, it's
5294 // supposed to have st_name == 0, but instead, it points to an index
5295 @@ -200,45 +200,45 @@ static Elf32_Sym libdl_symtab[] = {
5296 { st_name: sizeof(ANDROID_LIBDL_STRTAB) - 1,
5298 { st_name: 0, // starting index of the name in libdl_info.strtab
5299 - st_value: (Elf32_Addr) &android_dlopen,
5300 + st_value: (Elf_Addr) &android_dlopen,
5301 st_info: STB_GLOBAL << 4,
5305 - st_value: (Elf32_Addr) &android_dlclose,
5306 + st_value: (Elf_Addr) &android_dlclose,
5307 st_info: STB_GLOBAL << 4,
5311 - st_value: (Elf32_Addr) &android_dlsym,
5312 + st_value: (Elf_Addr) &android_dlsym,
5313 st_info: STB_GLOBAL << 4,
5317 - st_value: (Elf32_Addr) &android_dlerror,
5318 + st_value: (Elf_Addr) &android_dlerror,
5319 st_info: STB_GLOBAL << 4,
5323 - st_value: (Elf32_Addr) &android_dladdr,
5324 + st_value: (Elf_Addr) &android_dladdr,
5325 st_info: STB_GLOBAL << 4,
5328 #ifdef ANDROID_ARM_LINKER
5330 - st_value: (Elf32_Addr) &android_dl_unwind_find_exidx,
5331 + st_value: (Elf_Addr) &android_dl_unwind_find_exidx,
5332 st_info: STB_GLOBAL << 4,
5335 #elif defined(ANDROID_X86_LINKER)
5337 - st_value: (Elf32_Addr) &android_dl_iterate_phdr,
5338 + st_value: (Elf_Addr) &android_dl_iterate_phdr,
5339 st_info: STB_GLOBAL << 4,
5342 #elif defined(ANDROID_SH_LINKER)
5344 - st_value: (Elf32_Addr) &android_dl_iterate_phdr,
5345 + st_value: (Elf_Addr) &android_dl_iterate_phdr,
5346 st_info: STB_GLOBAL << 4,
5349 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/common/jb/linker.c
5350 +++ libhybris-0.1.0+git20131207+e452e83/hybris/common/jb/linker.c
5351 @@ -381,10 +381,10 @@ android_dl_iterate_phdr(int (*cb)(struct
5355 -static Elf32_Sym *_elf_lookup(soinfo *si, unsigned hash, const char *name)
5356 +static Elf_Sym *_elf_lookup(soinfo *si, unsigned hash, const char *name)
5359 - Elf32_Sym *symtab = si->symtab;
5361 + Elf_Sym *symtab = si->symtab;
5362 const char *strtab = si->strtab;
5365 @@ -426,11 +426,11 @@ static unsigned elfhash(const char *_nam
5371 _do_lookup(soinfo *si, const char *name, unsigned *base)
5373 unsigned elf_hash = elfhash(name);
5379 @@ -502,17 +502,17 @@ done:
5380 /* This is used by dl_sym(). It performs symbol lookup only within the
5381 specified soinfo object and not in any of its dependencies.
5383 -Elf32_Sym *lookup_in_library(soinfo *si, const char *name)
5384 +Elf_Sym *lookup_in_library(soinfo *si, const char *name)
5386 return _elf_lookup(si, elfhash(name), name);
5389 /* This is used by dl_sym(). It performs a global symbol lookup.
5391 -Elf32_Sym *lookup(const char *name, soinfo **found, soinfo *start)
5392 +Elf_Sym *lookup(const char *name, soinfo **found, soinfo *start)
5394 unsigned elf_hash = elfhash(name);
5395 - Elf32_Sym *s = NULL;
5396 + Elf_Sym *s = NULL;
5400 @@ -553,7 +553,7 @@ soinfo *find_containing_library(const vo
5404 -Elf32_Sym *find_containing_symbol(const void *addr, soinfo *si)
5405 +Elf_Sym *find_containing_symbol(const void *addr, soinfo *si)
5408 unsigned soaddr = (unsigned)addr - si->base;
5409 @@ -561,7 +561,7 @@ Elf32_Sym *find_containing_symbol(const
5410 /* Search the library's symbol table for any defined symbol which
5411 * contains this address */
5412 for(i=0; i<si->nchain; i++) {
5413 - Elf32_Sym *sym = &si->symtab[i];
5414 + Elf_Sym *sym = &si->symtab[i];
5416 if(sym->st_shndx != SHN_UNDEF &&
5417 soaddr >= sym->st_value &&
5418 @@ -576,7 +576,7 @@ Elf32_Sym *find_containing_symbol(const
5420 static void dump(soinfo *si)
5422 - Elf32_Sym *s = si->symtab;
5423 + Elf_Sym *s = si->symtab;
5426 for(n = 0; n < si->nchain; n++) {
5427 @@ -705,7 +705,7 @@ is_prelinked(int fd, const char *name)
5429 verify_elf_object(void *base, const char *name)
5431 - Elf32_Ehdr *hdr = (Elf32_Ehdr *) base;
5432 + Elf_Ehdr *hdr = (Elf_Ehdr *) base;
5434 if (hdr->e_ident[EI_MAG0] != ELFMAG0) return -1;
5435 if (hdr->e_ident[EI_MAG1] != ELFMAG1) return -1;
5436 @@ -750,8 +750,8 @@ get_lib_extents(int fd, const char *name
5437 unsigned min_vaddr = 0xffffffff;
5438 unsigned max_vaddr = 0;
5439 unsigned char *_hdr = (unsigned char *)__hdr;
5440 - Elf32_Ehdr *ehdr = (Elf32_Ehdr *)_hdr;
5442 + Elf_Ehdr *ehdr = (Elf_Ehdr *)_hdr;
5446 TRACE("[ %5d Computing extents for '%s'. ]\n", pid, name);
5447 @@ -770,7 +770,7 @@ get_lib_extents(int fd, const char *name
5448 TRACE("[ %5d - Non-prelinked library '%s' found. ]\n", pid, name);
5451 - phdr = (Elf32_Phdr *)(_hdr + ehdr->e_phoff);
5452 + phdr = (Elf_Phdr *)(_hdr + ehdr->e_phoff);
5454 /* find the min/max p_vaddrs from all the PT_LOAD segments so we can
5456 @@ -885,12 +885,12 @@ err:
5458 load_segments(int fd, void *header, soinfo *si)
5460 - Elf32_Ehdr *ehdr = (Elf32_Ehdr *)header;
5461 - Elf32_Phdr *phdr = (Elf32_Phdr *)((unsigned char *)header + ehdr->e_phoff);
5462 - Elf32_Addr base = (Elf32_Addr) si->base;
5463 + Elf_Ehdr *ehdr = (Elf_Ehdr *)header;
5464 + Elf_Phdr *phdr = (Elf_Phdr *)((unsigned char *)header + ehdr->e_phoff);
5465 + Elf_Addr base = (Elf_Addr) si->base;
5470 unsigned char *pbase;
5471 unsigned char *extra_base;
5473 @@ -956,7 +956,7 @@ load_segments(int fd, void *header, soin
5475 * _+---------------------+ page boundary
5477 - tmp = (Elf32_Addr)(((unsigned)pbase + len + PAGE_SIZE - 1) &
5478 + tmp = (Elf_Addr)(((unsigned)pbase + len + PAGE_SIZE - 1) &
5480 if (tmp < (base + phdr->p_vaddr + phdr->p_memsz)) {
5481 extra_len = base + phdr->p_vaddr + phdr->p_memsz - tmp;
5482 @@ -1020,7 +1020,7 @@ load_segments(int fd, void *header, soin
5483 phdr->p_vaddr, phdr->p_memsz);
5486 - si->gnu_relro_start = (Elf32_Addr) (base + phdr->p_vaddr);
5487 + si->gnu_relro_start = (Elf_Addr) (base + phdr->p_vaddr);
5488 si->gnu_relro_len = (unsigned) phdr->p_memsz;
5490 #ifdef ANDROID_ARM_LINKER
5491 @@ -1067,11 +1067,11 @@ fail:
5495 -get_wr_offset(int fd, const char *name, Elf32_Ehdr *ehdr)
5496 +get_wr_offset(int fd, const char *name, Elf_Ehdr *ehdr)
5498 - Elf32_Shdr *shdr_start;
5500 - int shdr_sz = ehdr->e_shnum * sizeof(Elf32_Shdr);
5501 + Elf_Shdr *shdr_start;
5503 + int shdr_sz = ehdr->e_shnum * sizeof(Elf_Shdr);
5505 unsigned wr_offset = 0xffffffff;
5507 @@ -1104,7 +1104,7 @@ load_library(const char *name)
5515 DL_ERR("Library '%s' not found", name);
5516 @@ -1161,8 +1161,8 @@ load_library(const char *name)
5518 /* this might not be right. Technically, we don't even need this info
5519 * once we go through 'load_segments'. */
5520 - hdr = (Elf32_Ehdr *)si->base;
5521 - si->phdr = (Elf32_Phdr *)((unsigned char *)si->base + hdr->e_phoff);
5522 + hdr = (Elf_Ehdr *)si->base;
5523 + si->phdr = (Elf_Phdr *)((unsigned char *)si->base + hdr->e_phoff);
5524 si->phnum = hdr->e_phnum;
5527 @@ -1261,7 +1261,7 @@ unsigned unload_library(soinfo *si)
5528 * in link_image. This is needed to undo the DT_NEEDED hack below.
5530 if ((si->gnu_relro_start != 0) && (si->gnu_relro_len != 0)) {
5531 - Elf32_Addr start = (si->gnu_relro_start & ~PAGE_MASK);
5532 + Elf_Addr start = (si->gnu_relro_start & ~PAGE_MASK);
5533 unsigned len = (si->gnu_relro_start - start) + si->gnu_relro_len;
5534 if (mprotect((void *) start, len, PROT_READ | PROT_WRITE) < 0)
5535 DL_ERR("%5d %s: could not undo GNU_RELRO protections. "
5536 @@ -1304,16 +1304,16 @@ unsigned unload_library(soinfo *si)
5539 /* TODO: don't use unsigned for addrs below. It works, but is not
5540 - * ideal. They should probably be either uint32_t, Elf32_Addr, or unsigned
5541 + * ideal. They should probably be either uint32_t, Elf_Addr, or unsigned
5544 -static int reloc_library(soinfo *si, Elf32_Rel *rel, unsigned count)
5545 +static int reloc_library(soinfo *si, Elf_Rel *rel, unsigned count)
5547 - Elf32_Sym *symtab = si->symtab;
5548 + Elf_Sym *symtab = si->symtab;
5549 const char *strtab = si->strtab;
5553 - Elf32_Rel *start = rel;
5554 + Elf_Rel *start = rel;
5557 for (idx = 0; idx < count; ++idx) {
5558 @@ -1712,7 +1712,7 @@ static int nullify_closed_stdio (void)
5559 static int link_image(soinfo *si, unsigned wr_offset)
5562 - Elf32_Phdr *phdr = si->phdr;
5563 + Elf_Phdr *phdr = si->phdr;
5564 int phnum = si->phnum;
5566 INFO("[ %5d linking %s ]\n", pid, si->name);
5567 @@ -1795,7 +1795,7 @@ static int link_image(soinfo *si, unsign
5568 phdr->p_vaddr, phdr->p_memsz);
5571 - si->gnu_relro_start = (Elf32_Addr) (si->base + phdr->p_vaddr);
5572 + si->gnu_relro_start = (Elf_Addr) (si->base + phdr->p_vaddr);
5573 si->gnu_relro_len = (unsigned) phdr->p_memsz;
5576 @@ -1822,7 +1822,7 @@ static int link_image(soinfo *si, unsign
5577 si->strtab = (const char *) (si->base + *d);
5580 - si->symtab = (Elf32_Sym *) (si->base + *d);
5581 + si->symtab = (Elf_Sym *) (si->base + *d);
5585 @@ -1831,13 +1831,13 @@ static int link_image(soinfo *si, unsign
5589 - si->plt_rel = (Elf32_Rel*) (si->base + *d);
5590 + si->plt_rel = (Elf_Rel*) (si->base + *d);
5593 si->plt_rel_count = *d / 8;
5596 - si->rel = (Elf32_Rel*) (si->base + *d);
5597 + si->rel = (Elf_Rel*) (si->base + *d);
5600 si->rel_count = *d / 8;
5601 @@ -1869,7 +1869,7 @@ static int link_image(soinfo *si, unsign
5602 pid, si->name, si->init_array);
5604 case DT_INIT_ARRAYSZ:
5605 - si->init_array_count = ((unsigned)*d) / sizeof(Elf32_Addr);
5606 + si->init_array_count = ((unsigned)*d) / sizeof(Elf_Addr);
5609 si->fini_array = (unsigned *)(si->base + *d);
5610 @@ -1877,7 +1877,7 @@ static int link_image(soinfo *si, unsign
5611 pid, si->name, si->fini_array);
5613 case DT_FINI_ARRAYSZ:
5614 - si->fini_array_count = ((unsigned)*d) / sizeof(Elf32_Addr);
5615 + si->fini_array_count = ((unsigned)*d) / sizeof(Elf_Addr);
5617 case DT_PREINIT_ARRAY:
5618 si->preinit_array = (unsigned *)(si->base + *d);
5619 @@ -1885,7 +1885,7 @@ static int link_image(soinfo *si, unsign
5620 pid, si->name, si->preinit_array);
5622 case DT_PREINIT_ARRAYSZ:
5623 - si->preinit_array_count = ((unsigned)*d) / sizeof(Elf32_Addr);
5624 + si->preinit_array_count = ((unsigned)*d) / sizeof(Elf_Addr);
5627 /* TODO: make use of this. */
5628 @@ -1987,7 +1987,7 @@ static int link_image(soinfo *si, unsign
5631 if (si->gnu_relro_start != 0 && si->gnu_relro_len != 0) {
5632 - Elf32_Addr start = (si->gnu_relro_start & ~PAGE_MASK);
5633 + Elf_Addr start = (si->gnu_relro_start & ~PAGE_MASK);
5634 unsigned len = (si->gnu_relro_start - start) + si->gnu_relro_len;
5635 if (mprotect((void *) start, len, PROT_READ) < 0) {
5636 DL_ERR("%5d GNU_RELRO mprotect of library '%s' failed: %d (%s)\n",
5637 @@ -2170,7 +2170,7 @@ sanitize:
5638 while(vecs[0] != 0){
5641 - si->phdr = (Elf32_Phdr*) vecs[1];
5642 + si->phdr = (Elf_Phdr*) vecs[1];
5645 si->phnum = (int) vecs[1];
5646 @@ -2190,7 +2190,7 @@ sanitize:
5648 for ( nn = 0; nn < si->phnum; nn++ ) {
5649 if (si->phdr[nn].p_type == PT_PHDR) {
5650 - si->base = (Elf32_Addr) si->phdr - si->phdr[nn].p_vaddr;
5651 + si->base = (Elf_Addr) si->phdr - si->phdr[nn].p_vaddr;
5655 @@ -2303,9 +2303,9 @@ static unsigned find_linker_base(unsigne
5657 unsigned __linker_init(unsigned **elfdata) {
5658 unsigned linker_addr = find_linker_base(elfdata);
5659 - Elf32_Ehdr *elf_hdr = (Elf32_Ehdr *) linker_addr;
5660 - Elf32_Phdr *phdr =
5661 - (Elf32_Phdr *)((unsigned char *) linker_addr + elf_hdr->e_phoff);
5662 + Elf_Ehdr *elf_hdr = (Elf_Ehdr *) linker_addr;
5664 + (Elf_Phdr *)((unsigned char *) linker_addr + elf_hdr->e_phoff);
5667 memset(&linker_so, 0, sizeof(soinfo));
5668 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/common/jb/linker.h
5669 +++ libhybris-0.1.0+git20131207+e452e83/hybris/common/jb/linker.h
5671 #define PAGE_SIZE 4096
5672 #define PAGE_MASK 4095
5674 +#if defined(__x86_64__)
5675 +typedef Elf64_Ehdr Elf_Ehdr;
5676 +typedef Elf64_Shdr Elf_Shdr;
5677 +typedef Elf64_Sym Elf_Sym;
5678 +typedef Elf64_Addr Elf_Addr;
5679 +typedef Elf64_Phdr Elf_Phdr;
5680 +typedef Elf64_Half Elf_Half;
5681 +typedef Elf64_Rel Elf_Rel;
5682 +typedef Elf64_Rela Elf_Rela;
5684 +typedef Elf32_Ehdr Elf_Ehdr;
5685 +typedef Elf32_Shdr Elf_Shdr;
5686 +typedef Elf32_Sym Elf_Sym;
5687 +typedef Elf32_Addr Elf_Addr;
5688 +typedef Elf32_Phdr Elf_Phdr;
5689 +typedef Elf32_Half Elf_Half;
5690 +typedef Elf32_Rel Elf_Rel;
5691 +typedef Elf32_Rela Elf_Rela;
5694 void debugger_init();
5695 const char *addr_to_name(unsigned addr);
5697 @@ -55,10 +75,10 @@ struct link_map
5698 /* needed for dl_iterate_phdr to be passed to the callbacks provided */
5701 - Elf32_Addr dlpi_addr;
5702 + Elf_Addr dlpi_addr;
5703 const char *dlpi_name;
5704 - const Elf32_Phdr *dlpi_phdr;
5705 - Elf32_Half dlpi_phnum;
5706 + const Elf_Phdr *dlpi_phdr;
5707 + Elf_Half dlpi_phnum;
5711 @@ -90,7 +110,7 @@ typedef struct soinfo soinfo;
5714 const char name[SOINFO_NAME_LEN];
5720 @@ -107,7 +127,7 @@ struct soinfo
5724 - Elf32_Sym *symtab;
5729 @@ -116,10 +136,10 @@ struct soinfo
5733 - Elf32_Rel *plt_rel;
5735 unsigned plt_rel_count;
5741 unsigned *preinit_array;
5742 @@ -144,7 +164,7 @@ struct soinfo
5744 int constructors_called;
5746 - Elf32_Addr gnu_relro_start;
5747 + Elf_Addr gnu_relro_start;
5748 unsigned gnu_relro_len;
5751 @@ -202,10 +222,10 @@ extern soinfo libdl_info;
5753 soinfo *find_library(const char *name);
5754 unsigned unload_library(soinfo *si);
5755 -Elf32_Sym *lookup_in_library(soinfo *si, const char *name);
5756 -Elf32_Sym *lookup(const char *name, soinfo **found, soinfo *start);
5757 +Elf_Sym *lookup_in_library(soinfo *si, const char *name);
5758 +Elf_Sym *lookup(const char *name, soinfo **found, soinfo *start);
5759 soinfo *find_containing_library(const void *addr);
5760 -Elf32_Sym *find_containing_symbol(const void *addr, soinfo *si);
5761 +Elf_Sym *find_containing_symbol(const void *addr, soinfo *si);
5762 const char *linker_get_error(void);
5763 void call_constructors_recursive(soinfo *si);
5765 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/common/jb/linker_format.c
5766 +++ libhybris-0.1.0+git20131207+e452e83/hybris/common/jb/linker_format.c
5767 @@ -268,7 +268,7 @@ static int log_vprint(int prio, const ch
5768 result = vformat_buffer(buf, sizeof buf, fmt, args);
5771 - log_fd = open("/dev/log/main", O_WRONLY);
5772 + log_fd = open("/dev/alog/main", O_WRONLY);
5774 log_fd = fileno(stdout); // kernel doesn't have android log
5776 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/configure.ac
5777 +++ libhybris-0.1.0+git20131207+e452e83/hybris/configure.ac
5778 @@ -184,6 +184,8 @@ AC_CONFIG_FILES([
5787 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/hardware/hardware.c
5788 +++ libhybris-0.1.0+git20131207+e452e83/hybris/hardware/hardware.c
5794 #include <android/hardware/hardware.h>
5795 #include <hybris/internal/binding.h>
5797 @@ -26,15 +27,20 @@ static int (*_hw_get_module)(const char
5799 static int (*_hw_get_module_by_class)(const char *class_id, const char *inst, const struct hw_module_t **module) = NULL;
5801 -#define HARDWARE_DLSYM(fptr, sym) do { if (_libhardware == NULL) { _init_lib_hardware(); }; if (*(fptr) == NULL) { *(fptr) = (void *) android_dlsym(_libhardware, sym); } } while (0)
5802 +#define HARDWARE_DLSYM(fptr, sym) do { if (*(fptr) == NULL) { *(fptr) = (void *) android_dlsym(_libhardware, sym); } } while (0)
5804 -static void _init_lib_hardware()
5805 +static void *_init_lib_hardware()
5807 - _libhardware = (void *) android_dlopen("/system/lib/libhardware.so", RTLD_LAZY);
5808 + if (!_libhardware)
5809 + _libhardware = (void *) android_dlopen("/system/lib/libhardware.so", RTLD_LAZY);
5810 + return _libhardware;
5813 int hw_get_module(const char *id, const struct hw_module_t **module)
5815 + if (!_init_lib_hardware())
5818 HARDWARE_DLSYM(&_hw_get_module, "hw_get_module");
5819 return (*_hw_get_module)(id, module);
5821 @@ -42,6 +48,9 @@ int hw_get_module(const char *id, const
5822 int hw_get_module_by_class(const char *class_id, const char *inst,
5823 const struct hw_module_t **module)
5825 + if (!_init_lib_hardware())
5828 HARDWARE_DLSYM(&_hw_get_module_by_class, "hw_get_module_by_class");
5829 return (*_hw_get_module_by_class)(class_id, inst, module);
5831 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/include/Makefile.am
5832 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/Makefile.am
5833 @@ -65,6 +65,15 @@ propertiesincludedir = $(includedir)/hyb
5834 propertiesinclude_HEADERS = \
5835 hybris/properties/properties.h
5837 +mediaincludedir = $(includedir)/hybris/media
5838 +mediainclude_HEADERS = \
5839 + hybris/media/media_compatibility_layer.h \
5840 + hybris/media/media_codec_layer.h \
5841 + hybris/media/media_codec_list.h \
5842 + hybris/media/media_format_layer.h \
5843 + hybris/media/surface_texture_client_hybris.h \
5844 + hybris/media/recorder_compatibility_layer.h
5846 dlfcnincludedir = $(includedir)/hybris/dlfcn
5847 dlfcninclude_HEADERS = \
5848 hybris/dlfcn/dlfcn.h
5849 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/include/hybris/input/input_stack_compatibility_layer.h
5850 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/input/input_stack_compatibility_layer.h
5851 @@ -109,6 +109,7 @@ extern "C" {
5852 int input_area_height;
5855 + int android_input_check_availability();
5856 void android_input_stack_initialize(
5857 struct AndroidEventListener* listener,
5858 struct InputStackConfiguration* input_stack_configuration);
5859 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/include/hybris/internal/camera_control.h
5860 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/internal/camera_control.h
5863 #include <camera/Camera.h>
5864 #include <camera/CameraParameters.h>
5865 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
5866 #include <gui/SurfaceTexture.h>
5868 +#include <gui/GLConsumer.h>
5873 @@ -31,15 +35,22 @@ extern "C" {
5874 struct CameraControlListener;
5876 struct CameraControl : public android::CameraListener,
5877 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
5878 public android::SurfaceTexture::FrameAvailableListener
5880 + public android::GLConsumer::FrameAvailableListener
5883 android::Mutex guard;
5884 CameraControlListener* listener;
5885 android::sp<android::Camera> camera;
5886 android::CameraParameters camera_parameters;
5887 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=2
5888 android::sp<android::SurfaceTexture> preview_texture;
5890 - // From android::SurfaceTexture::FrameAvailableListener
5892 + android::sp<android::GLConsumer> preview_texture;
5894 + // From android::SurfaceTexture/GLConsumer::FrameAvailableListener
5895 void onFrameAvailable();
5897 // From android::CameraListener
5898 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/include/hybris/internal/surface_flinger_compatibility_layer_internal.h
5899 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/internal/surface_flinger_compatibility_layer_internal.h
5902 #include <utils/misc.h>
5904 +#include <gui/Surface.h>
5905 #include <gui/SurfaceComposerClient.h>
5906 #include <ui/PixelFormat.h>
5907 #include <ui/Region.h>
5909 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/media_codec_layer.h
5912 + * Copyright (C) 2013 Canonical Ltd
5914 + * Licensed under the Apache License, Version 2.0 (the "License");
5915 + * you may not use this file except in compliance with the License.
5916 + * You may obtain a copy of the License at
5918 + * http://www.apache.org/licenses/LICENSE-2.0
5920 + * Unless required by applicable law or agreed to in writing, software
5921 + * distributed under the License is distributed on an "AS IS" BASIS,
5922 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5923 + * See the License for the specific language governing permissions and
5924 + * limitations under the License.
5926 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
5929 +#ifndef MEDIA_CODEC_LAYER_H_
5930 +#define MEDIA_CODEC_LAYER_H_
5932 +#include <stdint.h>
5933 +#include <unistd.h>
5935 +#ifdef SIMPLE_PLAYER
5936 +#include <media/stagefright/MediaCodec.h>
5939 +#include <hybris/media/media_format_layer.h>
5940 +#include <hybris/media/surface_texture_client_hybris.h>
5946 + typedef void* MediaCodecDelegate;
5948 + typedef void (*on_texture_needs_update)(void *context);
5949 + void media_codec_set_texture_needs_update_cb(MediaCodecDelegate delegate, on_texture_needs_update cb, void *context);
5951 + MediaCodecDelegate media_codec_create_by_codec_name(const char *name);
5952 + MediaCodecDelegate media_codec_create_by_codec_type(const char *type);
5954 +#ifdef SIMPLE_PLAYER
5955 + android::MediaCodec* media_codec_get(MediaCodecDelegate delegate);
5958 + void media_codec_delegate_destroy(MediaCodecDelegate delegate);
5959 + void media_codec_delegate_ref(MediaCodecDelegate delegate);
5960 + void media_codec_delegate_unref(MediaCodecDelegate delegate);
5962 +#ifdef SIMPLE_PLAYER
5963 + int media_codec_configure(MediaCodecDelegate delegate, MediaFormat format, void *nativeWindow, uint32_t flags);
5965 + int media_codec_configure(MediaCodecDelegate delegate, MediaFormat format, SurfaceTextureClientHybris stc, uint32_t flags);
5967 + int media_codec_set_surface_texture_client(MediaCodecDelegate delegate, SurfaceTextureClientHybris stc);
5969 + int media_codec_queue_csd(MediaCodecDelegate delegate, MediaFormat format);
5970 + int media_codec_start(MediaCodecDelegate delegate);
5971 + int media_codec_stop(MediaCodecDelegate delegate);
5972 + int media_codec_release(MediaCodecDelegate delegate);
5973 + int media_codec_flush(MediaCodecDelegate delegate);
5974 + size_t media_codec_get_input_buffers_size(MediaCodecDelegate delegate);
5975 + uint8_t *media_codec_get_nth_input_buffer(MediaCodecDelegate delegate, size_t n);
5976 + size_t media_codec_get_nth_input_buffer_capacity(MediaCodecDelegate delegate, size_t n);
5977 + size_t media_codec_get_output_buffers_size(MediaCodecDelegate delegate);
5978 + uint8_t *media_codec_get_nth_output_buffer(MediaCodecDelegate delegate, size_t n);
5979 + size_t media_codec_get_nth_output_buffer_capacity(MediaCodecDelegate delegate, size_t n);
5981 + struct _MediaCodecBufferInfo
5986 + int64_t presentation_time_us;
5988 + uint8_t render_retries;
5990 + typedef struct _MediaCodecBufferInfo MediaCodecBufferInfo;
5992 + int media_codec_dequeue_output_buffer(MediaCodecDelegate delegate, MediaCodecBufferInfo *info, int64_t timeout_us);
5993 + int media_codec_queue_input_buffer(MediaCodecDelegate delegate, const MediaCodecBufferInfo *info);
5994 + int media_codec_dequeue_input_buffer(MediaCodecDelegate delegate, size_t *index, int64_t timeout_us);
5995 + int media_codec_release_output_buffer(MediaCodecDelegate delegate, size_t index, uint8_t render);
5997 + MediaFormat media_codec_get_output_format(MediaCodecDelegate delegate);
6003 +#endif // MEDIA_CODEC_LAYER_H_
6005 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/media_codec_list.h
6008 + * Copyright (C) 2013 Canonical Ltd
6010 + * Licensed under the Apache License, Version 2.0 (the "License");
6011 + * you may not use this file except in compliance with the License.
6012 + * You may obtain a copy of the License at
6014 + * http://www.apache.org/licenses/LICENSE-2.0
6016 + * Unless required by applicable law or agreed to in writing, software
6017 + * distributed under the License is distributed on an "AS IS" BASIS,
6018 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6019 + * See the License for the specific language governing permissions and
6020 + * limitations under the License.
6022 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6025 +#ifndef MEDIA_CODEC_LIST_PRIV_H_
6026 +#define MEDIA_CODEC_LIST_PRIV_H_
6028 +#include <stddef.h>
6029 +#include <stdbool.h>
6030 +#include <unistd.h>
6036 + ssize_t media_codec_list_find_codec_by_type(const char *type, bool encoder, size_t startIndex);
6037 + ssize_t media_codec_list_find_codec_by_name(const char *name);
6038 + size_t media_codec_list_count_codecs();
6039 + void media_codec_list_get_codec_info_at_id(size_t index);
6040 + const char *media_codec_list_get_codec_name(size_t index);
6041 + bool media_codec_list_is_encoder(size_t index);
6042 + size_t media_codec_list_get_num_supported_types(size_t index);
6043 + size_t media_codec_list_get_nth_supported_type_len(size_t index, size_t n);
6044 + int media_codec_list_get_nth_supported_type(size_t index, char *type, size_t n);
6046 + struct _profile_level
6051 + typedef struct _profile_level profile_level;
6053 + size_t media_codec_list_get_num_profile_levels(size_t index, const char*);
6054 + size_t media_codec_list_get_num_color_formats(size_t index, const char*);
6055 + int media_codec_list_get_nth_codec_profile_level(size_t index, const char *type, profile_level *pro_level, size_t n);
6056 + int media_codec_list_get_codec_color_formats(size_t index, const char *type, uint32_t *color_formats);
6062 +#endif // MEDIA_CODEC_LIST_PRIV_H_
6064 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/media_compatibility_layer.h
6067 + * Copyright (C) 2013 Canonical Ltd
6069 + * Licensed under the Apache License, Version 2.0 (the "License");
6070 + * you may not use this file except in compliance with the License.
6071 + * You may obtain a copy of the License at
6073 + * http://www.apache.org/licenses/LICENSE-2.0
6075 + * Unless required by applicable law or agreed to in writing, software
6076 + * distributed under the License is distributed on an "AS IS" BASIS,
6077 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6078 + * See the License for the specific language governing permissions and
6079 + * limitations under the License.
6081 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6084 +#ifndef MEDIA_COMPATIBILITY_LAYER_H_
6085 +#define MEDIA_COMPATIBILITY_LAYER_H_
6087 +#include <stdint.h>
6088 +#include <unistd.h>
6089 +#include <stdbool.h>
6091 +#include <GLES2/gl2.h>
6097 + // Common compat calls
6098 + int media_compat_check_availability();
6101 + typedef void (*on_msg_set_video_size)(int height, int width, void *context);
6102 + typedef void (*on_video_texture_needs_update)(void *context);
6103 + typedef void (*on_msg_error)(void *context);
6104 + typedef void (*on_playback_complete)(void *context);
6105 + typedef void (*on_media_prepared)(void *context);
6107 + struct MediaPlayerWrapper;
6109 + // ----- Start of C API ----- //
6111 + // Callback setters
6112 + void android_media_set_video_size_cb(struct MediaPlayerWrapper *mp, on_msg_set_video_size cb, void *context);
6113 + void android_media_set_video_texture_needs_update_cb(struct MediaPlayerWrapper *mp, on_video_texture_needs_update cb, void *context);
6114 + void android_media_set_error_cb(struct MediaPlayerWrapper *mp, on_msg_error cb, void *context);
6115 + void android_media_set_playback_complete_cb(struct MediaPlayerWrapper *mp, on_playback_complete cb, void *context);
6116 + void android_media_set_media_prepared_cb(struct MediaPlayerWrapper *mp, on_media_prepared cb, void *context);
6118 + // Main player control API
6119 + struct MediaPlayerWrapper *android_media_new_player();
6120 + int android_media_set_data_source(struct MediaPlayerWrapper *mp, const char* url);
6121 + int android_media_set_preview_texture(struct MediaPlayerWrapper *mp, int texture_id);
6122 + void android_media_update_surface_texture(struct MediaPlayerWrapper *mp);
6123 + void android_media_surface_texture_get_transformation_matrix(struct MediaPlayerWrapper *mp, GLfloat*matrix);
6124 + int android_media_play(struct MediaPlayerWrapper *mp);
6125 + int android_media_pause(struct MediaPlayerWrapper *mp);
6126 + int android_media_stop(struct MediaPlayerWrapper *mp);
6127 + bool android_media_is_playing(struct MediaPlayerWrapper *mp);
6129 + int android_media_seek_to(struct MediaPlayerWrapper *mp, int msec);
6130 + int android_media_get_current_position(struct MediaPlayerWrapper *mp, int *msec);
6131 + int android_media_get_duration(struct MediaPlayerWrapper *mp, int *msec);
6133 + int android_media_get_volume(struct MediaPlayerWrapper *mp, int *volume);
6134 + int android_media_set_volume(struct MediaPlayerWrapper *mp, int volume);
6140 +#endif // MEDIA_COMPATIBILITY_LAYER_H_
6142 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/media_format_layer.h
6145 + * Copyright (C) 2013 Canonical Ltd
6147 + * Licensed under the Apache License, Version 2.0 (the "License");
6148 + * you may not use this file except in compliance with the License.
6149 + * You may obtain a copy of the License at
6151 + * http://www.apache.org/licenses/LICENSE-2.0
6153 + * Unless required by applicable law or agreed to in writing, software
6154 + * distributed under the License is distributed on an "AS IS" BASIS,
6155 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6156 + * See the License for the specific language governing permissions and
6157 + * limitations under the License.
6159 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6162 +#ifndef MEDIA_FORMAT_LAYER_H_
6163 +#define MEDIA_FORMAT_LAYER_H_
6165 +#include <stddef.h>
6166 +#include <unistd.h>
6172 + typedef void* MediaFormat;
6174 + MediaFormat media_format_create_video_format(const char *mime, int32_t width, int32_t height, int64_t duration_us, int32_t max_input_size);
6176 + void media_format_destroy(MediaFormat format);
6177 + void media_format_ref(MediaFormat format);
6178 + void media_format_unref(MediaFormat format);
6180 + void media_format_set_byte_buffer(MediaFormat format, const char *key, uint8_t *data, size_t size);
6182 + const char* media_format_get_mime(MediaFormat format);
6183 + int64_t media_format_get_duration_us(MediaFormat format);
6184 + int32_t media_format_get_width(MediaFormat format);
6185 + int32_t media_format_get_height(MediaFormat format);
6186 + int32_t media_format_get_max_input_size(MediaFormat format);
6187 + int32_t media_format_get_stride(MediaFormat format);
6188 + int32_t media_format_get_slice_height(MediaFormat format);
6189 + int32_t media_format_get_color_format(MediaFormat format);
6190 + int32_t media_format_get_crop_left(MediaFormat format);
6191 + int32_t media_format_get_crop_right(MediaFormat format);
6192 + int32_t media_format_get_crop_top(MediaFormat format);
6193 + int32_t media_format_get_crop_bottom(MediaFormat format);
6195 + // TODO: Add getter for CSD buffer
6201 +#endif // MEDIA_FORMAT_LAYER_H_
6203 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/recorder_compatibility_layer.h
6206 + * Copyright (C) 2013 Canonical Ltd
6208 + * Licensed under the Apache License, Version 2.0 (the "License");
6209 + * you may not use this file except in compliance with the License.
6210 + * You may obtain a copy of the License at
6212 + * http://www.apache.org/licenses/LICENSE-2.0
6214 + * Unless required by applicable law or agreed to in writing, software
6215 + * distributed under the License is distributed on an "AS IS" BASIS,
6216 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6217 + * See the License for the specific language governing permissions and
6218 + * limitations under the License.
6221 +#ifndef RECORDER_COMPATIBILITY_LAYER_H_
6222 +#define RECORDER_COMPATIBILITY_LAYER_H_
6224 +#include <stdint.h>
6225 +#include <unistd.h>
6226 +#include <stdint.h>
6227 +#include <stdbool.h>
6233 + struct MediaRecorderWrapper;
6234 + struct CameraControl;
6236 + // values are from andoid /frameworks/av/include/media/mediarecorder.h
6239 + ANDROID_VIDEO_SOURCE_DEFAULT = 0,
6240 + ANDROID_VIDEO_SOURCE_CAMERA = 1,
6241 + ANDROID_VIDEO_SOURCE_GRALLOC_BUFFER = 2
6244 + // values are from andoid /system/core/include/system/audio.h
6247 + ANDROID_AUDIO_SOURCE_DEFAULT = 0,
6248 + ANDROID_AUDIO_SOURCE_MIC = 1,
6249 + ANDROID_AUDIO_SOURCE_VOICE_UPLINK = 2,
6250 + ANDROID_AUDIO_SOURCE_VOICE_DOWNLINK = 3,
6251 + ANDROID_AUDIO_SOURCE_VOICE_CALL = 4,
6252 + ANDROID_AUDIO_SOURCE_CAMCORDER = 5,
6253 + ANDROID_AUDIO_SOURCE_VOICE_RECOGNITION = 6,
6254 + ANDROID_AUDIO_SOURCE_VOICE_COMMUNICATION = 7,
6255 + ANDROID_AUDIO_SOURCE_REMOTE_SUBMIX = 8,
6256 + ANDROID_AUDIO_SOURCE_CNT,
6257 + ANDROID_AUDIO_SOURCE_MAX = ANDROID_AUDIO_SOURCE_CNT - 1
6260 + // values are from andoid /frameworks/av/include/media/mediarecorder.h
6263 + ANDROID_OUTPUT_FORMAT_DEFAULT = 0,
6264 + ANDROID_OUTPUT_FORMAT_THREE_GPP = 1,
6265 + ANDROID_OUTPUT_FORMAT_MPEG_4 = 2,
6266 + ANDROID_OUTPUT_FORMAT_AUDIO_ONLY_START = 3,
6267 + /* These are audio only file formats */
6268 + ANDROID_OUTPUT_FORMAT_RAW_AMR = 3, //to be backward compatible
6269 + ANDROID_OUTPUT_FORMAT_AMR_NB = 3,
6270 + ANDROID_OUTPUT_FORMAT_AMR_WB = 4,
6271 + ANDROID_OUTPUT_FORMAT_AAC_ADIF = 5,
6272 + ANDROID_OUTPUT_FORMAT_AAC_ADTS = 6,
6273 + /* Stream over a socket, limited to a single stream */
6274 + ANDROID_OUTPUT_FORMAT_RTP_AVP = 7,
6275 + /* H.264/AAC data encapsulated in MPEG2/TS */
6276 + ANDROID_OUTPUT_FORMAT_MPEG2TS = 8
6279 + // values are from andoid /frameworks/av/include/media/mediarecorder.h
6282 + ANDROID_VIDEO_ENCODER_DEFAULT = 0,
6283 + ANDROID_VIDEO_ENCODER_H263 = 1,
6284 + ANDROID_VIDEO_ENCODER_H264 = 2,
6285 + ANDROID_VIDEO_ENCODER_MPEG_4_SP = 3
6288 + // values are from andoid /frameworks/av/include/media/mediarecorder.h
6291 + ANDROID_AUDIO_ENCODER_DEFAULT = 0,
6292 + ANDROID_AUDIO_ENCODER_AMR_NB = 1,
6293 + ANDROID_AUDIO_ENCODER_AMR_WB = 2,
6294 + ANDROID_AUDIO_ENCODER_AAC = 3,
6295 + ANDROID_AUDIO_ENCODER_HE_AAC = 4,
6296 + ANDROID_AUDIO_ENCODER_AAC_ELD = 5
6300 + typedef void (*on_recorder_msg_error)(void *context);
6302 + // Callback setters
6303 + void android_recorder_set_error_cb(struct MediaRecorderWrapper *mr, on_recorder_msg_error cb,
6306 + // Main recorder control API
6307 + struct MediaRecorderWrapper *android_media_new_recorder();
6308 + int android_recorder_initCheck(struct MediaRecorderWrapper *mr);
6309 + int android_recorder_setCamera(struct MediaRecorderWrapper *mr, struct CameraControl* control);
6310 + int android_recorder_setVideoSource(struct MediaRecorderWrapper *mr, VideoSource vs);
6311 + int android_recorder_setAudioSource(struct MediaRecorderWrapper *mr, AudioSource as);
6312 + int android_recorder_setOutputFormat(struct MediaRecorderWrapper *mr, OutputFormat of);
6313 + int android_recorder_setVideoEncoder(struct MediaRecorderWrapper *mr, VideoEncoder ve);
6314 + int android_recorder_setAudioEncoder(struct MediaRecorderWrapper *mr, AudioEncoder ae);
6315 + int android_recorder_setOutputFile(struct MediaRecorderWrapper *mr, int fd);
6316 + int android_recorder_setVideoSize(struct MediaRecorderWrapper *mr, int width, int height);
6317 + int android_recorder_setVideoFrameRate(struct MediaRecorderWrapper *mr, int frames_per_second);
6318 + int android_recorder_setParameters(struct MediaRecorderWrapper *mr, const char* parameters);
6319 + int android_recorder_start(struct MediaRecorderWrapper *mr);
6320 + int android_recorder_stop(struct MediaRecorderWrapper *mr);
6321 + int android_recorder_prepare(struct MediaRecorderWrapper *mr);
6322 + int android_recorder_reset(struct MediaRecorderWrapper *mr);
6323 + int android_recorder_close(struct MediaRecorderWrapper *mr);
6324 + int android_recorder_release(struct MediaRecorderWrapper *mr);
6332 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/media/surface_texture_client_hybris.h
6335 + * Copyright (C) 2013 Canonical Ltd
6337 + * Licensed under the Apache License, Version 2.0 (the "License");
6338 + * you may not use this file except in compliance with the License.
6339 + * You may obtain a copy of the License at
6341 + * http://www.apache.org/licenses/LICENSE-2.0
6343 + * Unless required by applicable law or agreed to in writing, software
6344 + * distributed under the License is distributed on an "AS IS" BASIS,
6345 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6346 + * See the License for the specific language governing permissions and
6347 + * limitations under the License.
6349 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6352 +#ifndef SURFACE_TEXTURE_CLIENT_HYBRIS_H_
6353 +#define SURFACE_TEXTURE_CLIENT_HYBRIS_H_
6355 +#include <stdint.h>
6356 +#include <unistd.h>
6358 +#include <EGL/egl.h>
6360 +#ifdef __ARM_PCS_VFP
6361 +#define FP_ATTRIB __attribute__((pcs("aapcs")))
6370 + // Taken from native_window.h
6372 + WINDOW_FORMAT_RGBA_8888 = 1,
6373 + WINDOW_FORMAT_RGBX_8888 = 2,
6374 + WINDOW_FORMAT_RGB_565 = 4,
6377 + typedef void* SurfaceTextureClientHybris;
6379 + //SurfaceTextureClientHybris surface_texture_client_get_instance();
6380 + SurfaceTextureClientHybris surface_texture_client_create(EGLNativeWindowType native_window);
6381 + SurfaceTextureClientHybris surface_texture_client_create_by_id(unsigned int texture_id);
6382 + uint8_t surface_texture_client_is_ready_for_rendering(SurfaceTextureClientHybris stc);
6383 + uint8_t surface_texture_client_hardware_rendering(SurfaceTextureClientHybris stc);
6384 + void surface_texture_client_set_hardware_rendering(SurfaceTextureClientHybris stc, uint8_t hardware_rendering);
6385 + void surface_texture_client_get_transformation_matrix(SurfaceTextureClientHybris stc, float *matrix) FP_ATTRIB;
6386 + void surface_texture_client_update_texture(SurfaceTextureClientHybris stc);
6387 + void surface_texture_client_destroy(SurfaceTextureClientHybris stc);
6388 + void surface_texture_client_ref(SurfaceTextureClientHybris stc);
6389 + void surface_texture_client_unref(SurfaceTextureClientHybris stc);
6390 + void surface_texture_client_set_surface_texture(SurfaceTextureClientHybris stc, EGLNativeWindowType native_window);
6396 +#endif // SURFACE_TEXTURE_CLIENT_HYBRIS_H_
6397 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/include/hybris/ui/ui_compatibility_layer.h
6398 +++ libhybris-0.1.0+git20131207+e452e83/hybris/include/hybris/ui/ui_compatibility_layer.h
6399 @@ -50,8 +50,10 @@ extern "C" {
6401 void* graphic_buffer_get_native_buffer(struct graphic_buffer *buffer);
6403 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
6404 void graphic_buffer_set_index(struct graphic_buffer *buffer, int index);
6405 int graphic_buffer_get_index(struct graphic_buffer *buffer);
6408 int graphic_buffer_init_check(struct graphic_buffer *buffer);
6410 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/input/is.c
6411 +++ libhybris-0.1.0+git20131207+e452e83/hybris/input/is.c
6414 HYBRIS_LIBRARY_INITIALIZE(is, COMPAT_LIBRARY_PATH);
6416 +int android_input_check_availability()
6418 + /* Both are defined via HYBRIS_LIBRARY_INITIALIZE */
6420 + hybris_is_initialize();
6421 + return is_handle ? 1 : 0;
6424 HYBRIS_IMPLEMENT_VOID_FUNCTION2(is, android_input_stack_initialize,
6425 struct AndroidEventListener*, struct InputStackConfiguration*);
6426 HYBRIS_IMPLEMENT_VOID_FUNCTION0(is, android_input_stack_start);
6428 +++ libhybris-0.1.0+git20131207+e452e83/hybris/media/Makefile.am
6430 +lib_LTLIBRARIES = \
6433 +libmedia_la_SOURCES = media.c
6434 +libmedia_la_CFLAGS = -I$(top_srcdir)/include
6436 +libmedia_la_CFLAGS += -DDEBUG
6439 +libmedia_la_CFLAGS += -ggdb -O0
6441 +libmedia_la_LDFLAGS = \
6442 + $(top_builddir)/common/libhybris-common.la \
6443 + -version-info "1":"0":"0"
6445 +pkgconfigdir = $(libdir)/pkgconfig
6446 +pkgconfig_DATA = libmedia.pc
6448 +++ libhybris-0.1.0+git20131207+e452e83/hybris/media/libmedia.pc.in
6451 +exec_prefix=${prefix}
6453 +includedir=@includedir@
6456 +Description: libhybris media library
6458 +Libs: -L${libdir} -lhybris-common -lmedia
6459 +Cflags: -I${includedir}
6461 +++ libhybris-0.1.0+git20131207+e452e83/hybris/media/media.c
6464 + * Copyright (C) 2013 Canonical Ltd
6466 + * Licensed under the Apache License, Version 2.0 (the "License");
6467 + * you may not use this file except in compliance with the License.
6468 + * You may obtain a copy of the License at
6470 + * http://www.apache.org/licenses/LICENSE-2.0
6472 + * Unless required by applicable law or agreed to in writing, software
6473 + * distributed under the License is distributed on an "AS IS" BASIS,
6474 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6475 + * See the License for the specific language governing permissions and
6476 + * limitations under the License.
6478 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6479 + * Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
6482 +#include <assert.h>
6484 +#include <stddef.h>
6485 +#include <stdbool.h>
6487 +#include <hybris/internal/binding.h>
6488 +#include <hybris/media/media_compatibility_layer.h>
6489 +#include <hybris/media/recorder_compatibility_layer.h>
6490 +#include <hybris/media/media_codec_layer.h>
6491 +#include <hybris/media/media_codec_list.h>
6492 +#include <hybris/media/media_format_layer.h>
6493 +#include <hybris/media/surface_texture_client_hybris.h>
6495 +#define COMPAT_LIBRARY_PATH "/system/lib/libmedia_compat_layer.so"
6497 +#ifdef __ARM_PCS_VFP
6498 +#define FP_ATTRIB __attribute__((pcs("aapcs")))
6503 +HYBRIS_LIBRARY_INITIALIZE(media, COMPAT_LIBRARY_PATH);
6505 +int media_compat_check_availability()
6507 + /* Both are defined via HYBRIS_LIBRARY_INITIALIZE */
6508 + hybris_media_initialize();
6509 + return media_handle ? 1 : 0;
6512 +HYBRIS_IMPLEMENT_FUNCTION0(media, struct MediaPlayerWrapper*,
6513 + android_media_new_player);
6514 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, android_media_update_surface_texture,
6515 + struct MediaPlayerWrapper*);
6516 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_media_play,
6517 + struct MediaPlayerWrapper*);
6518 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_media_pause,
6519 + struct MediaPlayerWrapper*);
6520 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_media_stop,
6521 + struct MediaPlayerWrapper*);
6522 +HYBRIS_IMPLEMENT_FUNCTION1(media, bool, android_media_is_playing,
6523 + struct MediaPlayerWrapper*);
6524 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_media_seek_to,
6525 + struct MediaPlayerWrapper*, int);
6528 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_media_set_data_source,
6529 + struct MediaPlayerWrapper*, const char*);
6530 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_media_set_preview_texture,
6531 + struct MediaPlayerWrapper*, int);
6532 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_media_set_volume,
6533 + struct MediaPlayerWrapper*, int);
6536 +HYBRIS_IMPLEMENT_VOID_FUNCTION2(media, android_media_surface_texture_get_transformation_matrix,
6537 + struct MediaPlayerWrapper*, float*);
6538 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_media_get_current_position,
6539 + struct MediaPlayerWrapper*, int*);
6540 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_media_get_duration,
6541 + struct MediaPlayerWrapper*, int*);
6542 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_media_get_volume,
6543 + struct MediaPlayerWrapper*, int*);
6546 +HYBRIS_IMPLEMENT_VOID_FUNCTION3(media, android_media_set_video_size_cb,
6547 + struct MediaPlayerWrapper*, on_msg_set_video_size, void*);
6548 +HYBRIS_IMPLEMENT_VOID_FUNCTION3(media, android_media_set_video_texture_needs_update_cb,
6549 + struct MediaPlayerWrapper*, on_video_texture_needs_update, void*);
6550 +HYBRIS_IMPLEMENT_VOID_FUNCTION3(media, android_media_set_error_cb,
6551 + struct MediaPlayerWrapper*, on_msg_error, void*);
6552 +HYBRIS_IMPLEMENT_VOID_FUNCTION3(media, android_media_set_playback_complete_cb,
6553 + struct MediaPlayerWrapper*, on_playback_complete, void*);
6554 +HYBRIS_IMPLEMENT_VOID_FUNCTION3(media, android_media_set_media_prepared_cb,
6555 + struct MediaPlayerWrapper*, on_media_prepared, void*);
6558 +HYBRIS_IMPLEMENT_FUNCTION1(media, MediaCodecDelegate,
6559 + media_codec_create_by_codec_name, const char*);
6560 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, media_codec_delegate_destroy,
6561 + MediaCodecDelegate);
6562 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, media_codec_delegate_ref,
6563 + MediaCodecDelegate);
6564 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, media_codec_delegate_unref,
6565 + MediaCodecDelegate);
6567 +#ifdef SIMPLE_PLAYER
6568 +HYBRIS_IMPLEMENT_FUNCTION4(media, int, media_codec_configure,
6569 + MediaCodecDelegate, MediaFormat, void*, uint32_t);
6571 +HYBRIS_IMPLEMENT_FUNCTION4(media, int, media_codec_configure,
6572 + MediaCodecDelegate, MediaFormat, SurfaceTextureClientHybris, uint32_t);
6574 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, media_codec_set_surface_texture_client,
6575 + MediaCodecDelegate, SurfaceTextureClientHybris);
6576 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, media_codec_queue_csd,
6577 + MediaCodecDelegate, MediaFormat);
6578 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, media_codec_start,
6579 + MediaCodecDelegate);
6580 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, media_codec_stop,
6581 + MediaCodecDelegate);
6582 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, media_codec_release,
6583 + MediaCodecDelegate);
6584 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, media_codec_flush,
6585 + MediaCodecDelegate);
6586 +HYBRIS_IMPLEMENT_FUNCTION1(media, size_t, media_codec_get_input_buffers_size,
6587 + MediaCodecDelegate);
6588 +HYBRIS_IMPLEMENT_FUNCTION2(media, uint8_t*, media_codec_get_nth_input_buffer,
6589 + MediaCodecDelegate, size_t);
6590 +HYBRIS_IMPLEMENT_FUNCTION2(media, size_t, media_codec_get_nth_input_buffer_capacity,
6591 + MediaCodecDelegate, size_t);
6592 +HYBRIS_IMPLEMENT_FUNCTION1(media, size_t, media_codec_get_output_buffers_size,
6593 + MediaCodecDelegate);
6594 +HYBRIS_IMPLEMENT_FUNCTION2(media, uint8_t*, media_codec_get_nth_output_buffer,
6595 + MediaCodecDelegate, size_t);
6596 +HYBRIS_IMPLEMENT_FUNCTION2(media, size_t, media_codec_get_nth_output_buffer_capacity,
6597 + MediaCodecDelegate, size_t);
6598 +HYBRIS_IMPLEMENT_FUNCTION3(media, int, media_codec_dequeue_output_buffer,
6599 + MediaCodecDelegate, MediaCodecBufferInfo*, int64_t);
6600 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, media_codec_queue_input_buffer,
6601 + MediaCodecDelegate, const MediaCodecBufferInfo*);
6602 +HYBRIS_IMPLEMENT_FUNCTION3(media, int, media_codec_dequeue_input_buffer,
6603 + MediaCodecDelegate, size_t*, int64_t);
6604 +HYBRIS_IMPLEMENT_FUNCTION3(media, int, media_codec_release_output_buffer,
6605 + MediaCodecDelegate, size_t, uint8_t);
6606 +HYBRIS_IMPLEMENT_FUNCTION1(media, MediaFormat, media_codec_get_output_format,
6607 + MediaCodecDelegate);
6609 +HYBRIS_IMPLEMENT_FUNCTION3(media, ssize_t, media_codec_list_find_codec_by_type,
6610 + const char*, bool, size_t);
6611 +HYBRIS_IMPLEMENT_FUNCTION1(media, ssize_t, media_codec_list_find_codec_by_name,
6613 +HYBRIS_IMPLEMENT_FUNCTION0(media, size_t, media_codec_list_count_codecs);
6614 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, media_codec_list_get_codec_info_at_id,
6616 +HYBRIS_IMPLEMENT_FUNCTION1(media, const char*, media_codec_list_get_codec_name,
6618 +HYBRIS_IMPLEMENT_FUNCTION1(media, bool, media_codec_list_is_encoder,
6620 +HYBRIS_IMPLEMENT_FUNCTION1(media, size_t, media_codec_list_get_num_supported_types,
6622 +HYBRIS_IMPLEMENT_FUNCTION2(media, size_t, media_codec_list_get_nth_supported_type_len,
6624 +HYBRIS_IMPLEMENT_FUNCTION3(media, int, media_codec_list_get_nth_supported_type,
6625 + size_t, char *, size_t);
6626 +HYBRIS_IMPLEMENT_FUNCTION2(media, size_t, media_codec_list_get_num_profile_levels,
6627 + size_t, const char*);
6628 +HYBRIS_IMPLEMENT_FUNCTION2(media, size_t, media_codec_list_get_num_color_formats,
6629 + size_t, const char*);
6630 +HYBRIS_IMPLEMENT_FUNCTION4(media, int, media_codec_list_get_nth_codec_profile_level,
6631 + size_t, const char*, profile_level*, size_t);
6632 +HYBRIS_IMPLEMENT_FUNCTION3(media, int, media_codec_list_get_codec_color_formats,
6633 + size_t, const char*, uint32_t*);
6635 +HYBRIS_IMPLEMENT_FUNCTION5(media, MediaFormat, media_format_create_video_format,
6636 + const char*, int32_t, int32_t, int64_t, int32_t);
6637 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, media_format_destroy,
6639 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, media_format_ref,
6641 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, media_format_unref,
6643 +HYBRIS_IMPLEMENT_VOID_FUNCTION4(media, media_format_set_byte_buffer,
6644 + MediaFormat, const char*, uint8_t*, size_t);
6645 +HYBRIS_IMPLEMENT_FUNCTION1(media, const char*, media_format_get_mime,
6647 +HYBRIS_IMPLEMENT_FUNCTION1(media, int64_t, media_format_get_duration_us,
6649 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_width,
6651 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_height,
6653 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_max_input_size,
6655 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_stride,
6657 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_slice_height,
6659 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_color_format,
6661 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_crop_left,
6663 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_crop_right,
6665 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_crop_top,
6667 +HYBRIS_IMPLEMENT_FUNCTION1(media, int32_t, media_format_get_crop_bottom,
6670 +// SurfaceTextureClientHybris
6671 +HYBRIS_IMPLEMENT_FUNCTION1(media, SurfaceTextureClientHybris,
6672 + surface_texture_client_create, EGLNativeWindowType);
6673 +HYBRIS_IMPLEMENT_FUNCTION1(media, SurfaceTextureClientHybris,
6674 + surface_texture_client_create_by_id, unsigned int);
6675 +HYBRIS_IMPLEMENT_FUNCTION1(media, uint8_t,
6676 + surface_texture_client_is_ready_for_rendering, SurfaceTextureClientHybris);
6677 +HYBRIS_IMPLEMENT_FUNCTION1(media, uint8_t,
6678 + surface_texture_client_hardware_rendering, SurfaceTextureClientHybris);
6679 +HYBRIS_IMPLEMENT_VOID_FUNCTION2(media, surface_texture_client_set_hardware_rendering,
6680 + SurfaceTextureClientHybris, uint8_t);
6681 +HYBRIS_IMPLEMENT_VOID_FUNCTION2(media, surface_texture_client_get_transformation_matrix,
6682 + SurfaceTextureClientHybris, GLfloat*);
6683 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, surface_texture_client_update_texture,
6684 + SurfaceTextureClientHybris);
6685 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, surface_texture_client_destroy,
6686 + SurfaceTextureClientHybris);
6687 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, surface_texture_client_ref,
6688 + SurfaceTextureClientHybris);
6689 +HYBRIS_IMPLEMENT_VOID_FUNCTION1(media, surface_texture_client_unref,
6690 + SurfaceTextureClientHybris);
6691 +HYBRIS_IMPLEMENT_VOID_FUNCTION2(media, surface_texture_client_set_surface_texture,
6692 + SurfaceTextureClientHybris, EGLNativeWindowType);
6695 +HYBRIS_IMPLEMENT_FUNCTION0(media, struct MediaRecorderWrapper*,
6696 + android_media_new_recorder);
6697 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_recorder_initCheck,
6698 + struct MediaRecorderWrapper*);
6699 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setCamera,
6700 + struct MediaRecorderWrapper*, struct CameraControl*);
6701 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setVideoSource,
6702 + struct MediaRecorderWrapper*, VideoSource);
6703 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setAudioSource,
6704 + struct MediaRecorderWrapper*, AudioSource);
6705 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setOutputFormat,
6706 + struct MediaRecorderWrapper*, OutputFormat);
6707 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setVideoEncoder,
6708 + struct MediaRecorderWrapper*, VideoEncoder);
6709 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setAudioEncoder,
6710 + struct MediaRecorderWrapper*, AudioEncoder);
6711 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setOutputFile,
6712 + struct MediaRecorderWrapper*, int);
6713 +HYBRIS_IMPLEMENT_FUNCTION3(media, int, android_recorder_setVideoSize,
6714 + struct MediaRecorderWrapper*, int, int);
6715 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setVideoFrameRate,
6716 + struct MediaRecorderWrapper*, int);
6717 +HYBRIS_IMPLEMENT_FUNCTION2(media, int, android_recorder_setParameters,
6718 + struct MediaRecorderWrapper*, const char*);
6719 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_recorder_start,
6720 + struct MediaRecorderWrapper*);
6721 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_recorder_stop,
6722 + struct MediaRecorderWrapper*);
6723 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_recorder_prepare,
6724 + struct MediaRecorderWrapper*);
6725 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_recorder_reset,
6726 + struct MediaRecorderWrapper*);
6727 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_recorder_close,
6728 + struct MediaRecorderWrapper*);
6729 +HYBRIS_IMPLEMENT_FUNCTION1(media, int, android_recorder_release,
6730 + struct MediaRecorderWrapper*);
6732 +// Recorder Callbacks
6733 +HYBRIS_IMPLEMENT_VOID_FUNCTION3(media, android_recorder_set_error_cb,
6734 + struct MediaRecorderWrapper *, on_recorder_msg_error, void*);
6735 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/tests/Makefile.am
6736 +++ libhybris-0.1.0+git20131207+e452e83/hybris/tests/Makefile.am
6737 @@ -7,6 +7,8 @@ bin_PROGRAMS = \
6745 if HAS_ANDROID_4_2_0
6746 @@ -140,6 +142,28 @@ test_camera_LDADD = \
6747 $(top_builddir)/camera/libcamera.la \
6748 $(top_builddir)/input/libis.la
6750 +test_media_SOURCES = test_media.c
6751 +test_media_CFLAGS = \
6752 + -I$(top_srcdir)/include
6753 +test_media_LDADD = \
6754 + $(top_builddir)/common/libhybris-common.la \
6755 + $(top_builddir)/egl/libEGL.la \
6756 + $(top_builddir)/glesv2/libGLESv2.la \
6757 + $(top_builddir)/media/libmedia.la \
6758 + $(top_builddir)/sf/libsf.la
6760 +test_recorder_SOURCES = test_recorder.c
6761 +test_recorder_CFLAGS = \
6762 + -I$(top_srcdir)/include
6763 +test_recorder_LDADD = \
6764 + $(top_builddir)/common/libhybris-common.la \
6765 + $(top_builddir)/egl/libEGL.la \
6766 + $(top_builddir)/glesv2/libGLESv2.la \
6767 + $(top_builddir)/media/libmedia.la \
6768 + $(top_builddir)/camera/libcamera.la \
6769 + $(top_builddir)/input/libis.la \
6770 + $(top_builddir)/sf/libsf.la
6772 test_gps_SOURCES = test_gps.c
6773 test_gps_CFLAGS = -pthread \
6774 -I$(top_srcdir)/include \
6776 +++ libhybris-0.1.0+git20131207+e452e83/hybris/tests/test_media.c
6779 + * Copyright (C) 2013 Canonical Ltd
6781 + * Licensed under the Apache License, Version 2.0 (the "License");
6782 + * you may not use this file except in compliance with the License.
6783 + * You may obtain a copy of the License at
6785 + * http://www.apache.org/licenses/LICENSE-2.0
6787 + * Unless required by applicable law or agreed to in writing, software
6788 + * distributed under the License is distributed on an "AS IS" BASIS,
6789 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
6790 + * See the License for the specific language governing permissions and
6791 + * limitations under the License.
6793 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
6794 + * Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
6797 +#include <hybris/media/media_compatibility_layer.h>
6798 +#include <hybris/surface_flinger/surface_flinger_compatibility_layer.h>
6800 +#include <EGL/egl.h>
6801 +#include <GLES2/gl2.h>
6802 +#include <GLES2/gl2ext.h>
6804 +#include <assert.h>
6805 +#include <stdlib.h>
6807 +#include <string.h>
6808 +#include <stdbool.h>
6809 +#include <limits.h>
6811 +#include <unistd.h>
6812 +#include <sys/stat.h>
6813 +#include <sys/types.h>
6820 +static float DestWidth = 0.0, DestHeight = 0.0;
6821 +// Actual video dimmensions
6822 +static int Width = 0, Height = 0;
6824 +static GLuint gProgram;
6825 +static GLuint gaPositionHandle, gaTexHandle, gsTextureHandle, gmTexMatrix;
6827 +static GLfloat positionCoordinates[8];
6829 +struct MediaPlayerWrapper *player = NULL;
6831 +void calculate_position_coordinates()
6833 + // Assuming cropping output for now
6834 + float x = 1, y = 1;
6837 + x = (float) (Width / DestWidth);
6838 + y = (float) (Height / DestHeight);
6840 + // Make the larger side be 1
6849 + positionCoordinates[0] = -x;
6850 + positionCoordinates[1] = y;
6851 + positionCoordinates[2] = -x;
6852 + positionCoordinates[3] = -y;
6853 + positionCoordinates[4] = x;
6854 + positionCoordinates[5] = -y;
6855 + positionCoordinates[6] = x;
6856 + positionCoordinates[7] = y;
6859 +struct ClientWithSurface
6861 + struct SfClient* client;
6862 + struct SfSurface* surface;
6865 +struct ClientWithSurface client_with_surface(bool setup_surface_with_egl)
6867 + struct ClientWithSurface cs;
6869 + cs.client = sf_client_create();
6872 + printf("Problem creating client ... aborting now.");
6876 + static const size_t primary_display = 0;
6878 + DestWidth = sf_get_display_width(primary_display);
6879 + DestHeight = sf_get_display_height(primary_display);
6880 + printf("Primary display width: %f, height: %f\n", DestWidth, DestHeight);
6882 + SfSurfaceCreationParameters params = {
6887 + -1, //PIXEL_FORMAT_RGBA_8888,
6890 + setup_surface_with_egl, // Do not associate surface with egl, will be done by camera HAL
6891 + "MediaCompatLayerTestSurface"
6894 + cs.surface = sf_surface_create(cs.client, ¶ms);
6896 + if (!cs.surface) {
6897 + printf("Problem creating surface ... aborting now.");
6901 + sf_surface_make_current(cs.surface);
6906 +static const char *vertex_shader()
6909 + "attribute vec4 a_position; \n"
6910 + "attribute vec2 a_texCoord; \n"
6911 + "uniform mat4 m_texMatrix; \n"
6912 + "varying vec2 v_texCoord; \n"
6913 + "varying float topDown; \n"
6916 + " gl_Position = a_position; \n"
6917 + " v_texCoord = (m_texMatrix * vec4(a_texCoord, 0.0, 1.0)).xy;\n"
6921 +static const char *fragment_shader()
6924 + "#extension GL_OES_EGL_image_external : require \n"
6925 + "precision mediump float; \n"
6926 + "varying vec2 v_texCoord; \n"
6927 + "uniform samplerExternalOES s_texture; \n"
6930 + " gl_FragColor = texture2D( s_texture, v_texCoord );\n"
6934 +static GLuint loadShader(GLenum shaderType, const char* pSource)
6936 + GLuint shader = glCreateShader(shaderType);
6939 + glShaderSource(shader, 1, &pSource, NULL);
6940 + glCompileShader(shader);
6941 + GLint compiled = 0;
6942 + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
6945 + GLint infoLen = 0;
6946 + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
6948 + char* buf = (char*) malloc(infoLen);
6950 + glGetShaderInfoLog(shader, infoLen, NULL, buf);
6951 + fprintf(stderr, "Could not compile shader %d:\n%s\n",
6955 + glDeleteShader(shader);
6960 + printf("Error, during shader creation: %i\n", glGetError());
6966 +static GLuint create_program(const char* pVertexSource, const char* pFragmentSource)
6968 + GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource);
6969 + if (!vertexShader) {
6970 + printf("vertex shader not compiled\n");
6974 + GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource);
6975 + if (!pixelShader) {
6976 + printf("frag shader not compiled\n");
6980 + GLuint program = glCreateProgram();
6982 + glAttachShader(program, vertexShader);
6983 + glAttachShader(program, pixelShader);
6984 + glLinkProgram(program);
6985 + GLint linkStatus = GL_FALSE;
6987 + glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
6988 + if (linkStatus != GL_TRUE) {
6989 + GLint bufLength = 0;
6990 + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
6992 + char* buf = (char*) malloc(bufLength);
6994 + glGetProgramInfoLog(program, bufLength, NULL, buf);
6995 + fprintf(stderr, "Could not link program:\n%s\n", buf);
6999 + glDeleteProgram(program);
7007 +static int setup_video_texture(struct ClientWithSurface *cs, GLuint *preview_texture_id)
7009 + assert(cs != NULL);
7010 + assert(preview_texture_id != NULL);
7012 + sf_surface_make_current(cs->surface);
7014 + glGenTextures(1, preview_texture_id);
7015 + glClearColor(0, 0, 0, 0);
7016 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
7017 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
7018 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
7019 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
7021 + android_media_set_preview_texture(player, *preview_texture_id);
7026 +void set_video_size_cb(int height, int width, void *context)
7028 + printf("Video height: %d, width: %d\n", height, width);
7029 + printf("Video dest height: %f, width: %f\n", DestHeight, DestWidth);
7035 +void media_prepared_cb(void *context)
7037 + printf("Media is prepared for playback.\n");
7040 +int main(int argc, char **argv)
7043 + printf("Usage: test_media <video_to_play>\n");
7044 + return EXIT_FAILURE;
7047 + player = android_media_new_player();
7048 + if (player == NULL) {
7049 + printf("Problem creating new media player.\n");
7050 + return EXIT_FAILURE;
7053 + // Set player event cb for when the video size is known:
7054 + android_media_set_video_size_cb(player, set_video_size_cb, NULL);
7055 + android_media_set_media_prepared_cb(player, media_prepared_cb, NULL);
7057 + printf("Setting data source to: %s.\n", argv[1]);
7059 + if (android_media_set_data_source(player, argv[1]) != OK) {
7060 + printf("Failed to set data source: %s\n", argv[1]);
7061 + return EXIT_FAILURE;
7064 + printf("Creating EGL surface.\n");
7065 + struct ClientWithSurface cs = client_with_surface(true /* Associate surface with egl. */);
7066 + if (!cs.surface) {
7067 + printf("Problem acquiring surface for preview");
7068 + return EXIT_FAILURE;
7071 + printf("Creating GL texture.\n");
7073 + GLuint preview_texture_id;
7074 + EGLDisplay disp = sf_client_get_egl_display(cs.client);
7075 + EGLSurface surface = sf_surface_get_egl_surface(cs.surface);
7077 + sf_surface_make_current(cs.surface);
7079 + if (setup_video_texture(&cs, &preview_texture_id) != OK) {
7080 + printf("Problem setting up GL texture for video surface.\n");
7081 + return EXIT_FAILURE;
7084 + printf("Starting video playback.\n");
7085 + android_media_play(player);
7087 + while (android_media_is_playing(player)) {
7088 + GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
7090 + const GLfloat textureCoordinates[] = {
7097 + android_media_update_surface_texture(player);
7099 + calculate_position_coordinates();
7101 + gProgram = create_program(vertex_shader(), fragment_shader());
7102 + gaPositionHandle = glGetAttribLocation(gProgram, "a_position");
7103 + gaTexHandle = glGetAttribLocation(gProgram, "a_texCoord");
7104 + gsTextureHandle = glGetUniformLocation(gProgram, "s_texture");
7105 + gmTexMatrix = glGetUniformLocation(gProgram, "m_texMatrix");
7107 + glClear(GL_COLOR_BUFFER_BIT);
7109 + // Use the program object
7110 + glUseProgram(gProgram);
7111 + // Enable attributes
7112 + glEnableVertexAttribArray(gaPositionHandle);
7113 + glEnableVertexAttribArray(gaTexHandle);
7114 + // Load the vertex position
7115 + glVertexAttribPointer(gaPositionHandle,
7120 + positionCoordinates);
7121 + // Load the texture coordinate
7122 + glVertexAttribPointer(gaTexHandle,
7127 + textureCoordinates);
7129 + GLfloat matrix[16];
7130 + android_media_surface_texture_get_transformation_matrix(player, matrix);
7132 + glUniformMatrix4fv(gmTexMatrix, 1, GL_FALSE, matrix);
7134 + glActiveTexture(GL_TEXTURE0);
7135 + // Set the sampler texture unit to 0
7136 + glUniform1i(gsTextureHandle, 0);
7137 + glUniform1i(gmTexMatrix, 0);
7138 + android_media_update_surface_texture(player);
7139 + glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
7140 + //glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
7141 + glDisableVertexAttribArray(gaPositionHandle);
7142 + glDisableVertexAttribArray(gaTexHandle);
7144 + eglSwapBuffers(disp, surface);
7147 + android_media_stop(player);
7149 + return EXIT_SUCCESS;
7152 +++ libhybris-0.1.0+git20131207+e452e83/hybris/tests/test_recorder.c
7155 + * Copyright (C) 2013 Canonical Ltd
7157 + * Licensed under the Apache License, Version 2.0 (the "License");
7158 + * you may not use this file except in compliance with the License.
7159 + * You may obtain a copy of the License at
7161 + * http://www.apache.org/licenses/LICENSE-2.0
7163 + * Unless required by applicable law or agreed to in writing, software
7164 + * distributed under the License is distributed on an "AS IS" BASIS,
7165 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7166 + * See the License for the specific language governing permissions and
7167 + * limitations under the License.
7169 + * Authored by: Jim Hodapp <jim.hodapp@canonical.com>
7170 + * Guenter Schwann <guenter.schwann@canonical.com>
7171 + * Ricardo Salveti de Araujo <ricardo.salveti@canonical.com>
7174 +#include <hybris/camera/camera_compatibility_layer.h>
7175 +#include <hybris/camera/camera_compatibility_layer_capabilities.h>
7177 +#include <hybris/media/recorder_compatibility_layer.h>
7179 +#include <hybris/input/input_stack_compatibility_layer.h>
7180 +#include <hybris/input/input_stack_compatibility_layer_codes_key.h>
7181 +#include <hybris/input/input_stack_compatibility_layer_flags_key.h>
7183 +#include <hybris/surface_flinger/surface_flinger_compatibility_layer.h>
7185 +#include <EGL/egl.h>
7186 +#include <GLES2/gl2.h>
7187 +#include <GLES2/gl2ext.h>
7189 +#include <assert.h>
7190 +#include <stdlib.h>
7192 +#include <string.h>
7193 +#include <stdbool.h>
7194 +#include <limits.h>
7196 +#include <unistd.h>
7197 +#include <sys/stat.h>
7198 +#include <sys/types.h>
7200 +int shot_counter = 1;
7201 +int32_t current_zoom_level = 1;
7202 +bool new_camera_frame_available = true;
7203 +struct MediaRecorderWrapper *mr = 0;
7204 +GLuint preview_texture_id = 0;
7206 +static GLuint gProgram;
7207 +static GLuint gaPositionHandle, gaTexHandle, gsTextureHandle, gmTexMatrix;
7209 +void error_msg_cb(void* context)
7211 + printf("%s \n", __PRETTY_FUNCTION__);
7214 +void shutter_msg_cb(void* context)
7216 + printf("%s \n", __PRETTY_FUNCTION__);
7219 +void zoom_msg_cb(void* context, int32_t new_zoom_level)
7221 + printf("%s \n", __PRETTY_FUNCTION__);
7223 + struct CameraControl* cc = (struct CameraControl*) context;
7225 + current_zoom_level = new_zoom_level;
7228 +void autofocus_msg_cb(void* context)
7230 + printf("%s \n", __PRETTY_FUNCTION__);
7233 +void raw_data_cb(void* data, uint32_t data_size, void* context)
7235 + printf("%s: %d \n", __PRETTY_FUNCTION__, data_size);
7238 +void jpeg_data_cb(void* data, uint32_t data_size, void* context)
7240 + printf("%s: %d \n", __PRETTY_FUNCTION__, data_size);
7241 + struct CameraControl* cc = (struct CameraControl*) context;
7242 + android_camera_start_preview(cc);
7245 +void size_cb(void* ctx, int width, int height)
7247 + printf("Supported size: [%d,%d]\n", width, height);
7250 +void preview_texture_needs_update_cb(void* ctx)
7252 + new_camera_frame_available = true;
7255 +void on_new_input_event(struct Event* event, void* context)
7259 + if (event->type == KEY_EVENT_TYPE && event->action == ISCL_KEY_EVENT_ACTION_UP) {
7260 + printf("We have got a key event: %d \n", event->details.key.key_code);
7262 + struct CameraControl* cc = (struct CameraControl*) context;
7265 + switch (event->details.key.key_code) {
7266 + case ISCL_KEYCODE_VOLUME_UP:
7267 + printf("Starting video recording\n");
7269 + android_camera_unlock(cc);
7271 + ret = android_recorder_setCamera(mr, cc);
7273 + printf("android_recorder_setCamera() failed\n");
7276 + //state initial / idle
7277 + ret = android_recorder_setAudioSource(mr, ANDROID_AUDIO_SOURCE_CAMCORDER);
7279 + printf("android_recorder_setAudioSource() failed\n");
7282 + ret = android_recorder_setVideoSource(mr, ANDROID_VIDEO_SOURCE_CAMERA);
7284 + printf("android_recorder_setVideoSource() failed\n");
7287 + //state initialized
7288 + ret = android_recorder_setOutputFormat(mr, ANDROID_OUTPUT_FORMAT_MPEG_4);
7290 + printf("android_recorder_setOutputFormat() failed\n");
7293 + //state DataSourceConfigured
7294 + ret = android_recorder_setAudioEncoder(mr, ANDROID_AUDIO_ENCODER_AAC);
7296 + printf("android_recorder_setAudioEncoder() failed\n");
7299 + ret = android_recorder_setVideoEncoder(mr, ANDROID_VIDEO_ENCODER_H264);
7301 + printf("android_recorder_setVideoEncoder() failed\n");
7306 + fd = open("/tmp/test_video_recorder.avi", O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
7308 + printf("Could not open file for video recording\n");
7309 + printf("FD: %i\n", fd);
7312 + ret = android_recorder_setOutputFile(mr, fd);
7314 + printf("android_recorder_setOutputFile() failed\n");
7318 + ret = android_recorder_setVideoSize(mr, 1280, 720);
7320 + printf("android_recorder_setVideoSize() failed\n");
7323 + ret = android_recorder_setVideoFrameRate(mr, 30);
7325 + printf("android_recorder_setVideoFrameRate() failed\n");
7329 + ret = android_recorder_prepare(mr);
7331 + printf("android_recorder_prepare() failed\n");
7335 + ret = android_recorder_start(mr);
7337 + printf("android_recorder_start() failed\n");
7341 + case ISCL_KEYCODE_VOLUME_DOWN:
7342 + printf("Stoping video recording\n");
7343 + ret = android_recorder_stop(mr);
7345 + printf("Stoping video recording returned\n");
7347 + printf("android_recorder_stop() failed\n");
7350 + printf("Stopped video recording\n");
7351 + ret = android_recorder_reset(mr);
7353 + printf("android_recorder_reset() failed\n");
7356 + printf("Reset video recorder\n");
7362 +struct ClientWithSurface
7364 + struct SfClient* client;
7365 + struct SfSurface* surface;
7368 +struct ClientWithSurface client_with_surface(bool setup_surface_with_egl)
7370 + struct ClientWithSurface cs;
7372 + cs.client = sf_client_create();
7375 + printf("Problem creating client ... aborting now.");
7379 + static const size_t primary_display = 0;
7381 + SfSurfaceCreationParameters params = {
7384 + sf_get_display_width(primary_display),
7385 + sf_get_display_height(primary_display),
7386 + -1, //PIXEL_FORMAT_RGBA_8888,
7389 + setup_surface_with_egl, // Do not associate surface with egl, will be done by camera HAL
7390 + "CameraCompatLayerTestSurface"
7393 + cs.surface = sf_surface_create(cs.client, ¶ms);
7395 + if (!cs.surface) {
7396 + printf("Problem creating surface ... aborting now.");
7400 + sf_surface_make_current(cs.surface);
7405 +static const char* vertex_shader()
7408 + "#extension GL_OES_EGL_image_external : require \n"
7409 + "attribute vec4 a_position; \n"
7410 + "attribute vec2 a_texCoord; \n"
7411 + "uniform mat4 m_texMatrix; \n"
7412 + "varying vec2 v_texCoord; \n"
7413 + "varying float topDown; \n"
7416 + " gl_Position = a_position; \n"
7417 + " v_texCoord = a_texCoord; \n"
7418 + // " v_texCoord = (m_texMatrix * vec4(a_texCoord, 0.0, 1.0)).xy;\n"
7419 + //" topDown = v_texCoord.y; \n"
7423 +static const char* fragment_shader()
7426 + "#extension GL_OES_EGL_image_external : require \n"
7427 + "precision mediump float; \n"
7428 + "varying vec2 v_texCoord; \n"
7429 + "uniform samplerExternalOES s_texture; \n"
7432 + " gl_FragColor = texture2D( s_texture, v_texCoord );\n"
7436 +static GLuint loadShader(GLenum shaderType, const char* pSource) {
7437 + GLuint shader = glCreateShader(shaderType);
7440 + glShaderSource(shader, 1, &pSource, NULL);
7441 + glCompileShader(shader);
7442 + GLint compiled = 0;
7443 + glGetShaderiv(shader, GL_COMPILE_STATUS, &compiled);
7446 + GLint infoLen = 0;
7447 + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLen);
7449 + char* buf = (char*) malloc(infoLen);
7451 + glGetShaderInfoLog(shader, infoLen, NULL, buf);
7452 + fprintf(stderr, "Could not compile shader %d:\n%s\n",
7456 + glDeleteShader(shader);
7461 + printf("Error, during shader creation: %i\n", glGetError());
7467 +static GLuint create_program(const char* pVertexSource, const char* pFragmentSource) {
7468 + GLuint vertexShader = loadShader(GL_VERTEX_SHADER, pVertexSource);
7469 + if (!vertexShader) {
7470 + printf("vertex shader not compiled\n");
7474 + GLuint pixelShader = loadShader(GL_FRAGMENT_SHADER, pFragmentSource);
7475 + if (!pixelShader) {
7476 + printf("frag shader not compiled\n");
7480 + GLuint program = glCreateProgram();
7482 + glAttachShader(program, vertexShader);
7483 + glAttachShader(program, pixelShader);
7484 + glLinkProgram(program);
7485 + GLint linkStatus = GL_FALSE;
7487 + glGetProgramiv(program, GL_LINK_STATUS, &linkStatus);
7488 + if (linkStatus != GL_TRUE) {
7489 + GLint bufLength = 0;
7490 + glGetProgramiv(program, GL_INFO_LOG_LENGTH, &bufLength);
7492 + char* buf = (char*) malloc(bufLength);
7494 + glGetProgramInfoLog(program, bufLength, NULL, buf);
7495 + fprintf(stderr, "Could not link program:\n%s\n", buf);
7499 + glDeleteProgram(program);
7507 +int main(int argc, char** argv)
7509 + printf("Test application for video recording using the camera\n");
7510 + printf("Recording start with volume up button. And stops with volume down.\n");
7511 + printf("The result is stored to /root/test_video.avi\n\n");
7513 + struct CameraControlListener listener;
7514 + memset(&listener, 0, sizeof(listener));
7515 + listener.on_msg_error_cb = error_msg_cb;
7516 + listener.on_msg_shutter_cb = shutter_msg_cb;
7517 + listener.on_msg_focus_cb = autofocus_msg_cb;
7518 + listener.on_msg_zoom_cb = zoom_msg_cb;
7520 + listener.on_data_raw_image_cb = raw_data_cb;
7521 + listener.on_data_compressed_image_cb = jpeg_data_cb;
7522 + listener.on_preview_texture_needs_update_cb = preview_texture_needs_update_cb;
7523 + struct CameraControl* cc = android_camera_connect_to(BACK_FACING_CAMERA_TYPE,
7526 + printf("Problem connecting to camera");
7530 + listener.context = cc;
7532 + mr = android_media_new_recorder();
7534 + struct AndroidEventListener event_listener;
7535 + event_listener.on_new_event = on_new_input_event;
7536 + event_listener.context = cc;
7538 + struct InputStackConfiguration input_configuration = { false, 25000 };
7540 + android_input_stack_initialize(&event_listener, &input_configuration);
7541 + android_input_stack_start();
7543 + android_camera_dump_parameters(cc);
7545 + printf("Supported video sizes:\n");
7546 + android_camera_enumerate_supported_video_sizes(cc, size_cb, NULL);
7548 + int min_fps, max_fps, current_fps;
7550 + android_camera_set_preview_size(cc, 1280, 720);
7552 + int width, height;
7553 + android_camera_get_video_size(cc, &width, &height);
7554 + printf("Current video size: [%d,%d]\n", width, height);
7556 + struct ClientWithSurface cs = client_with_surface(true /* Associate surface with egl. */);
7558 + if (!cs.surface) {
7559 + printf("Problem acquiring surface for preview");
7563 + EGLDisplay disp = sf_client_get_egl_display(cs.client);
7564 + EGLSurface surface = sf_surface_get_egl_surface(cs.surface);
7566 + sf_surface_make_current(cs.surface);
7568 + gProgram = create_program(vertex_shader(), fragment_shader());
7569 + gaPositionHandle = glGetAttribLocation(gProgram, "a_position");
7570 + gaTexHandle = glGetAttribLocation(gProgram, "a_texCoord");
7571 + gsTextureHandle = glGetUniformLocation(gProgram, "s_texture");
7572 + gmTexMatrix = glGetUniformLocation(gProgram, "m_texMatrix");
7574 + glGenTextures(1, &preview_texture_id);
7575 + glClearColor(1.0, 0., 0.5, 1.);
7576 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
7577 + glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
7579 + GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
7581 + GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
7582 + android_camera_set_preview_texture(cc, preview_texture_id);
7583 + android_camera_start_preview(cc);
7585 + GLfloat transformation_matrix[16];
7586 + android_camera_get_preview_texture_transformation(cc, transformation_matrix);
7587 + glUniformMatrix4fv(gmTexMatrix, 1, GL_FALSE, transformation_matrix);
7589 + printf("Started camera preview.\n");
7592 + /*if (new_camera_frame_available)
7594 + printf("Updating texture");
7595 + new_camera_frame_available = false;
7597 + static GLfloat vVertices[] = { 0.0f, 0.0f, 0.0f, // Position 0
7598 + 0.0f, 0.0f, // TexCoord 0
7599 + 0.0f, 1.0f, 0.0f, // Position 1
7600 + 0.0f, 1.0f, // TexCoord 1
7601 + 1.0f, 1.0f, 0.0f, // Position 2
7602 + 1.0f, 1.0f, // TexCoord 2
7603 + 1.0f, 0.0f, 0.0f, // Position 3
7604 + 1.0f, 0.0f // TexCoord 3
7607 + GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
7609 + // Set the viewport
7610 + // Clear the color buffer
7611 + glClear(GL_COLOR_BUFFER_BIT);
7612 + // Use the program object
7613 + glUseProgram(gProgram);
7614 + // Enable attributes
7615 + glEnableVertexAttribArray(gaPositionHandle);
7616 + glEnableVertexAttribArray(gaTexHandle);
7617 + // Load the vertex position
7618 + glVertexAttribPointer(gaPositionHandle,
7622 + 5 * sizeof(GLfloat),
7624 + // Load the texture coordinate
7625 + glVertexAttribPointer(gaTexHandle,
7629 + 5 * sizeof(GLfloat),
7632 + glActiveTexture(GL_TEXTURE0);
7633 + // Set the sampler texture unit to 0
7634 + glUniform1i(gsTextureHandle, 0);
7635 + glUniform1i(gmTexMatrix, 0);
7636 + android_camera_update_preview_texture(cc);
7637 + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices);
7638 + glDisableVertexAttribArray(gaPositionHandle);
7639 + glDisableVertexAttribArray(gaTexHandle);
7641 + eglSwapBuffers(disp, surface);
7644 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/tests/test_ui.c
7645 +++ libhybris-0.1.0+git20131207+e452e83/hybris/tests/test_ui.c
7646 @@ -52,8 +52,10 @@ int main(int argc, char **argv)
7647 graphic_buffer_lock(buffer, GRALLOC_USAGE_HW_RENDER, &vaddr);
7648 graphic_buffer_unlock(buffer);
7650 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
7651 graphic_buffer_set_index(buffer, 11);
7652 assert(graphic_buffer_get_index(buffer) == 11);
7655 graphic_buffer_free(buffer);
7657 --- libhybris-0.1.0+git20131207+e452e83.orig/hybris/ui/ui.c
7658 +++ libhybris-0.1.0+git20131207+e452e83/hybris/ui/ui.c
7659 @@ -48,9 +48,11 @@ HYBRIS_IMPLEMENT_FUNCTION1(ui, uint32_t,
7660 struct graphic_buffer*);
7661 HYBRIS_IMPLEMENT_FUNCTION1(ui, void*, graphic_buffer_get_native_buffer,
7662 struct graphic_buffer*);
7663 +#if ANDROID_VERSION_MAJOR==4 && ANDROID_VERSION_MINOR<=3
7664 HYBRIS_IMPLEMENT_VOID_FUNCTION2(ui, graphic_buffer_set_index,
7665 struct graphic_buffer*, int);
7666 HYBRIS_IMPLEMENT_FUNCTION1(ui, int, graphic_buffer_get_index,
7667 struct graphic_buffer*);
7669 HYBRIS_IMPLEMENT_FUNCTION1(ui, int, graphic_buffer_init_check,
7670 struct graphic_buffer*);