summaryrefslogtreecommitdiff
Diffstat
-rw-r--r--tv_callback.h7
-rw-r--r--tv_input.cpp96
-rw-r--r--tvapi/android/include/ITv.h34
-rw-r--r--tvapi/android/include/ITvClient.h12
-rw-r--r--tvapi/android/include/ITvService.h18
-rw-r--r--tvapi/android/include/TvClient.h5
-rw-r--r--tvapi/android/include/tvcmd.h1180
-rw-r--r--tvapi/android/jni/cfbc_jni.cpp214
-rw-r--r--tvapi/android/jni/cfbc_test.cpp64
-rw-r--r--tvapi/android/jni/com_droidlogic_app_tv_TvControlManager.cpp666
-rw-r--r--tvapi/android/libtvbinder/ITv.cpp246
-rw-r--r--tvapi/android/libtvbinder/ITvClient.cpp78
-rw-r--r--tvapi/android/libtvbinder/ITvService.cpp56
-rw-r--r--tvapi/android/libtvbinder/TvClient.cpp54
-rw-r--r--tvapi/android/tv/TvPlay.cpp36
-rw-r--r--tvapi/android/tv/TvPlay.h2
-rw-r--r--tvapi/android/tvserver/TvService.cpp8700
-rw-r--r--tvapi/android/tvserver/TvService.h107
-rw-r--r--tvapi/android/tvserver/main.cpp12
-rw-r--r--tvapi/android/tvserver/tv_callback.h25
-rw-r--r--tvapi/libtv/audio/CAudioCustomerCtrl.cpp170
-rw-r--r--tvapi/libtv/audio/CAudioCustomerCtrl.h32
-rw-r--r--tvapi/libtv/audio/CTvAudio.h52
-rw-r--r--tvapi/libtv/audio/audio_alsa.cpp1004
-rw-r--r--tvapi/libtv/audio/audio_alsa.h164
-rw-r--r--tvapi/libtv/audio/audio_effect.cpp82
-rw-r--r--tvapi/libtv/audio/audio_effect.h34
-rw-r--r--tvapi/libtv/include/amstream.h142
-rw-r--r--tvapi/libtv/include/cm.h188
-rw-r--r--tvapi/libtv/include/hdmirx_cec.h492
-rw-r--r--tvapi/libtv/include/ve.h342
-rw-r--r--tvapi/libtv/tv/AutoBackLight.cpp280
-rw-r--r--tvapi/libtv/tv/AutoBackLight.h44
-rw-r--r--tvapi/libtv/tv/CAutoPQparam.cpp172
-rw-r--r--tvapi/libtv/tv/CAutoPQparam.h26
-rw-r--r--tvapi/libtv/tv/CAv.cpp612
-rw-r--r--tvapi/libtv/tv/CAv.h188
-rw-r--r--tvapi/libtv/tv/CFbcCommunication.cpp2670
-rw-r--r--tvapi/libtv/tv/CFbcCommunication.h716
-rw-r--r--tvapi/libtv/tv/CFrontEnd.cpp964
-rw-r--r--tvapi/libtv/tv/CFrontEnd.h236
-rw-r--r--tvapi/libtv/tv/CTv.cpp2174
-rw-r--r--tvapi/libtv/tv/CTv.h1470
-rw-r--r--tvapi/libtv/tv/CTvBooking.cpp170
-rw-r--r--tvapi/libtv/tv/CTvBooking.h94
-rw-r--r--tvapi/libtv/tv/CTvDmx.cpp8
-rw-r--r--tvapi/libtv/tv/CTvDmx.h12
-rw-r--r--tvapi/libtv/tv/CTvEpg.cpp258
-rw-r--r--tvapi/libtv/tv/CTvEpg.h276
-rw-r--r--tvapi/libtv/tv/CTvEv.cpp2
-rw-r--r--tvapi/libtv/tv/CTvEv.h322
-rw-r--r--tvapi/libtv/tv/CTvRecord.cpp368
-rw-r--r--tvapi/libtv/tv/CTvRecord.h70
-rw-r--r--tvapi/libtv/tv/CTvScanner.cpp1934
-rw-r--r--tvapi/libtv/tv/CTvScanner.h418
-rw-r--r--tvapi/libtv/tv/CTvScreenCapture.cpp1228
-rw-r--r--tvapi/libtv/tv/CTvScreenCapture.h142
-rw-r--r--tvapi/libtv/tv/CTvSubtitle.cpp708
-rw-r--r--tvapi/libtv/tv/CTvSubtitle.h430
-rw-r--r--tvapi/libtv/tv/CTvTime.h134
-rw-r--r--tvapi/libtv/tv/CTvVchipCheck.cpp250
-rw-r--r--tvapi/libtv/tv/CTvVchipCheck.h40
-rw-r--r--tvapi/libtv/tv/CUpgradeFBC.cpp974
-rw-r--r--tvapi/libtv/tv/CUpgradeFBC.h104
-rw-r--r--tvapi/libtv/tv/ScreenCatch.cpp638
-rw-r--r--tvapi/libtv/tvconfig/CIniFile.cpp558
-rw-r--r--tvapi/libtv/tvconfig/CIniFile.h76
-rw-r--r--tvapi/libtv/tvconfig/tvconfig.cpp28
-rw-r--r--tvapi/libtv/tvdb/CTvChannel.cpp408
-rw-r--r--tvapi/libtv/tvdb/CTvChannel.h478
-rw-r--r--tvapi/libtv/tvdb/CTvDatabase.cpp302
-rw-r--r--tvapi/libtv/tvdb/CTvDatabase.h112
-rw-r--r--tvapi/libtv/tvdb/CTvDimension.cpp714
-rw-r--r--tvapi/libtv/tvdb/CTvDimension.h134
-rw-r--r--tvapi/libtv/tvdb/CTvEvent.cpp322
-rw-r--r--tvapi/libtv/tvdb/CTvEvent.h112
-rw-r--r--tvapi/libtv/tvdb/CTvGroup.cpp4
-rw-r--r--tvapi/libtv/tvdb/CTvGroup.h14
-rw-r--r--tvapi/libtv/tvdb/CTvProgram.cpp1322
-rw-r--r--tvapi/libtv/tvdb/CTvProgram.h988
-rw-r--r--tvapi/libtv/tvdb/CTvRegion.cpp228
-rw-r--r--tvapi/libtv/tvdb/CTvRegion.h30
-rw-r--r--tvapi/libtv/tvin/CHDMIRxCEC.cpp830
-rw-r--r--tvapi/libtv/tvin/CSourceConnectDetect.cpp438
-rw-r--r--tvapi/libtv/tvin/CSourceConnectDetect.h76
-rw-r--r--tvapi/libtv/tvin/CTvin.cpp4452
-rw-r--r--tvapi/libtv/tvin/CTvin.h2116
-rw-r--r--tvapi/libtv/tvsetting/CBlobDevice.cpp6
-rw-r--r--tvapi/libtv/tvsetting/CBlobDevice.h72
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceE2prom.cpp12
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceE2prom.h48
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceFile.cpp66
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceFile.h20
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceRam.cpp146
-rw-r--r--tvapi/libtv/tvsetting/CBlobDeviceRam.h40
-rw-r--r--tvapi/libtv/tvsetting/CTvSetting.cpp2168
-rw-r--r--tvapi/libtv/tvsetting/CTvSettingDeviceFactory.cpp38
-rw-r--r--tvapi/libtv/tvsetting/CTvSettingDeviceFactory.h8
-rw-r--r--tvapi/libtv/tvsetting/TvKeyData.cpp1792
-rw-r--r--tvapi/libtv/tvsetting/audio_cfg.cpp958
-rw-r--r--tvapi/libtv/tvutils/CCondition.h84
-rw-r--r--tvapi/libtv/tvutils/CFile.cpp261
-rw-r--r--tvapi/libtv/tvutils/CFile.h50
-rw-r--r--tvapi/libtv/tvutils/CHdmiCecCmd.cpp6
-rw-r--r--tvapi/libtv/tvutils/CHdmiCecCmd.h6
-rw-r--r--tvapi/libtv/tvutils/CMsgQueue.cpp146
-rw-r--r--tvapi/libtv/tvutils/CMsgQueue.h40
-rw-r--r--tvapi/libtv/tvutils/CMutex.h112
-rw-r--r--tvapi/libtv/tvutils/CSerialCommunication.cpp118
-rw-r--r--tvapi/libtv/tvutils/CSerialCommunication.h60
-rw-r--r--tvapi/libtv/tvutils/CSerialPort.cpp568
-rw-r--r--tvapi/libtv/tvutils/CSerialPort.h42
-rw-r--r--tvapi/libtv/tvutils/CSqlite.cpp126
-rw-r--r--tvapi/libtv/tvutils/CSqlite.h288
-rw-r--r--tvapi/libtv/tvutils/CThread.cpp212
-rw-r--r--tvapi/libtv/tvutils/CThread.h76
-rw-r--r--tvapi/libtv/tvutils/CTvInput.cpp204
-rw-r--r--tvapi/libtv/tvutils/CTvInput.h46
-rw-r--r--tvapi/libtv/tvutils/serial_base.cpp560
-rw-r--r--tvapi/libtv/tvutils/serial_operate.cpp336
-rw-r--r--tvapi/libtv/tvutils/serial_operate.h42
-rw-r--r--tvapi/libtv/tvutils/tvutils.cpp2813
-rw-r--r--tvapi/libtv/tvutils/tvutils.h44
-rw-r--r--tvapi/libtv/tvutils/zepoll.cpp66
-rw-r--r--tvapi/libtv/tvutils/zepoll.h54
-rw-r--r--tvapi/libtv/version/version.cpp50
-rw-r--r--tvapi/libtv/vpp/CPQdb.cpp618
-rw-r--r--tvapi/libtv/vpp/CPQdb.h232
-rw-r--r--tvapi/libtv/vpp/CVpp.cpp724
-rw-r--r--tvapi/libtv/vpp/CVpp.h676
-rw-r--r--tvapi/libtv/vpp/pqdata.cpp216
-rw-r--r--tvapi/tvtests/comm_test.cpp42
-rw-r--r--tvapi/tvtests/ssm_test.cpp320
-rw-r--r--tvapi/tvtests/tvconfig_test.cpp560
134 files changed, 31073 insertions, 30287 deletions
diff --git a/tvapi/libtv/tv/ScreenCatch.cpp b/tvapi/libtv/tv/ScreenCatch.cpp
index 0ed084e..971ac91 100644
--- a/tvapi/libtv/tv/ScreenCatch.cpp
+++ b/tvapi/libtv/tv/ScreenCatch.cpp
@@ -56,324 +56,324 @@
namespace android {
- struct ScreenCatch::ScreenCatchClient : public BnScreenMediaSourceClient {
- ScreenCatchClient(void *user)
- {
- mUser = user;
- ALOGE("[%s %d] user:%x", __FUNCTION__, __LINE__, user);
- }
-
- virtual void notify(int msg, int ext1, int ext2, const Parcel *obj)
- {
- ALOGI("notify %d, %d, %d", msg, ext1, ext2);
- }
-
- virtual int dataCallback(const sp<IMemory> &data)
- {
- return 0;
- }
-
- protected:
- void *mUser;
- virtual ~ScreenCatchClient() {}
-
- private:
- DISALLOW_EVIL_CONSTRUCTORS(ScreenCatchClient);
- };
-
- ScreenCatch::ScreenCatch(uint32_t bufferWidth, uint32_t bufferHeight, uint32_t bitSize) :
- mWidth(ALIGN(bufferWidth)),
- mHeight(bufferHeight),
- mScreenMediaSourceService(NULL),
- mColorFormat(OMX_COLOR_Format32bitARGB8888),
- mBitSize(bitSize)
- {
- ALOGE("ScreenCatch: %dx%d", bufferWidth, bufferHeight);
-
- if (bufferWidth <= 0 || bufferHeight <= 0 || bufferWidth > 1920 || bufferHeight > 1080) {
- ALOGE("Invalid dimensions %dx%d", bufferWidth, bufferHeight);
- }
-
- if (bitSize != 24 || bitSize != 32)
- bitSize = 32;
-
- mCorpX = -1;
- mCorpY = -1;
- mCorpWidth = -1;
- mCorpHeight = -1;
-
- }
-
- ScreenCatch::~ScreenCatch()
- {
- ALOGE("~ScreenCatch");
- }
-
- void ScreenCatch::setVideoRotation(int degree)
- {
- int angle;
-
- ALOGI("[%s %d] setVideoRotation degree:%x", __FUNCTION__, __LINE__, degree);
-
- }
-
- void ScreenCatch::setVideoCrop(int x, int y, int width, int height)
- {
- mCorpX = x;
- mCorpY = y;
- mCorpWidth = width;
- mCorpHeight = height;
- }
-
- static inline void yuv_to_rgb32(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb)
- {
- register int r, g, b;
-
- r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10;
- g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u - 128) ) >> 10;
- b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10;
-
- r = r > 255 ? 255 : r < 0 ? 0 : r;
- g = g > 255 ? 255 : g < 0 ? 0 : g;
- b = b > 255 ? 255 : b < 0 ? 0 : b;
-
- /*ARGB*/
- *rgb = (unsigned char)r;
- rgb++;
- *rgb = (unsigned char)g;
- rgb++;
- *rgb = (unsigned char)b;
- rgb++;
- *rgb = 0xff;
-
- }
-
- void nv21_to_rgb32(unsigned char *buf, unsigned char *rgb, int width, int height)
- {
- int x, y, z = 0;
- int h, w;
- int blocks;
- unsigned char Y1, Y2, U, V;
-
- blocks = (width * height) * 2;
-
- for (h = 0, z = 0; h < height; h += 2) {
- for (y = 0; y < width * 2; y += 2) {
-
- Y1 = buf[ h * width + y + 0];
- V = buf[ blocks / 2 + h * width / 2 + y % width + 0 ];
- Y2 = buf[ h * width + y + 1];
- U = buf[ blocks / 2 + h * width / 2 + y % width + 1 ];
-
- yuv_to_rgb32(Y1, U, V, &rgb[z]);
- yuv_to_rgb32(Y2, U, V, &rgb[z + 4]);
- z += 8;
- }
- }
- }
-
- static inline void yuv_to_rgb24(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb)
- {
- register int r, g, b;
-
- r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10;
- g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u - 128) ) >> 10;
- b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10;
-
- r = r > 255 ? 255 : r < 0 ? 0 : r;
- g = g > 255 ? 255 : g < 0 ? 0 : g;
- b = b > 255 ? 255 : b < 0 ? 0 : b;
-
- /*ARGB*/
- *rgb = (unsigned char)r;
- rgb++;
- *rgb = (unsigned char)g;
- rgb++;
- *rgb = (unsigned char)b;
- }
-
- void nv21_to_rgb24(unsigned char *buf, unsigned char *rgb, int width, int height)
- {
- int x, y, z = 0;
- int h, w;
- int blocks;
- unsigned char Y1, Y2, U, V;
-
- blocks = (width * height) * 2;
-
- for (h = 0, z = 0; h < height; h += 2) {
- for (y = 0; y < width * 2; y += 2) {
-
- Y1 = buf[ h * width + y + 0];
- V = buf[ blocks / 2 + h * width / 2 + y % width + 0 ];
- Y2 = buf[ h * width + y + 1];
- U = buf[ blocks / 2 + h * width / 2 + y % width + 1 ];
-
- yuv_to_rgb24(Y1, U, V, &rgb[z]);
- yuv_to_rgb24(Y2, U, V, &rgb[z + 3]);
- z += 6;
- }
- }
- }
-
- int ScreenCatch::threadFunc()
- {
- int64_t pts;
- int status;
-
- sp<MemoryHeapBase> newMemoryHeap = new MemoryHeapBase(mWidth * mHeight * 3 / 2);
- sp<MemoryBase> buffer = new MemoryBase(newMemoryHeap, 0, mWidth * mHeight * 3 / 2);
-
- ALOGV("[%s %d] empty:%d", __FUNCTION__, __LINE__, mRawBufferQueue.empty());
-
- while (mStart == true) {
-
- status = mScreenMediaSourceService->readBuffer(mClientId, buffer, &pts);
-
- if (status != OK && mStart == true) {
- usleep(10000);
- continue;
- }
-
- if (mStart != true)
- break;
-
- MediaBuffer *accessUnit;
-
- if (OMX_COLOR_Format24bitRGB888 == mColorFormat) { //rgb 24bit
- accessUnit = new MediaBuffer(mWidth * mHeight * 3);
- nv21_to_rgb24((unsigned char *)buffer->pointer(), (unsigned char *)accessUnit->data(), mWidth, mHeight);
- accessUnit->set_range(0, mWidth * mHeight * 3);
- } else if (OMX_COLOR_Format32bitARGB8888 == mColorFormat) { //rgba 32bit
- accessUnit = new MediaBuffer(mWidth * mHeight * 4);
- nv21_to_rgb32((unsigned char *)buffer->pointer(), (unsigned char *)accessUnit->data(), mWidth, mHeight);
- accessUnit->set_range(0, mWidth * mHeight * 4);
- } else if (OMX_COLOR_FormatYUV420SemiPlanar == mColorFormat) { //nv21
- accessUnit = new MediaBuffer(mWidth * mHeight * 3 / 2);
- memcpy((unsigned char *)accessUnit->data(), (unsigned char *)buffer->pointer(), mWidth * mHeight * 3 / 2);
- accessUnit->set_range(0, mWidth * mHeight * 3 / 2);
- }
- mRawBufferQueue.push_back(accessUnit);
- }
-
- ALOGE("[%s %d] thread out", __FUNCTION__, __LINE__);
-
- mThreadOutCondition.signal();
-
- return 0;
- }
-
- void *ScreenCatch::ThreadWrapper(void *me)
- {
-
- ScreenCatch *Convertor = static_cast<ScreenCatch *>(me);
- Convertor->threadFunc();
- return NULL;
- }
-
- status_t ScreenCatch::start(MetaData *params)
- {
- ALOGE("[%s %d] mWidth:%d mHeight:%d", __FUNCTION__, __LINE__, mWidth, mHeight);
- Mutex::Autolock autoLock(mLock);
-
- status_t status;
- int64_t pts;
- int client_id;
-
- sp<IServiceManager> sm = defaultServiceManager();
- sp<IBinder> binder = sm->getService(String16("media.screenmediasource"));
- mScreenMediaSourceService = interface_cast<IScreenMediaSource>(binder);
-
- sp<ScreenCatchClient> mIScreenSourceClient = new ScreenCatchClient(this);
-
- ALOGE("[%s %d] mWidth:%d mHeight:%d", __FUNCTION__, __LINE__, mWidth, mHeight);
-
- mScreenMediaSourceService->registerClient(mIScreenSourceClient, mWidth, mHeight, 1, SCREENMEDIASOURC_RAWDATA_TYPE, &client_id, NULL);
-
- ALOGE("[%s %d] client_id:%d", __FUNCTION__, __LINE__, client_id);
-
- mClientId = client_id;
-
- if (status != OK) {
- ALOGE("setResolutionRatio fail");
- return !OK;
- }
-
- ALOGV("[%s %d] mCorpX:%d mCorpY:%d mCorpWidth:%d mCorpHeight:%d", __FUNCTION__, __LINE__, mCorpX, mCorpY, mCorpWidth, mCorpHeight);
-
- if (mCorpX != -1)
- mScreenMediaSourceService->setVideoCrop(client_id, mCorpX, mCorpY, mCorpWidth, mCorpHeight);
-
-
- status = mScreenMediaSourceService->start(client_id);
-
- if (status != OK) {
- mScreenMediaSourceService->unregisterClient(mClientId);
- ALOGE("ScreenMediaSourceService start fail");
- return !OK;
- }
-
- if (!(params->findInt32(kKeyColorFormat, &mColorFormat)
- && (mColorFormat != OMX_COLOR_FormatYUV420SemiPlanar
- || mColorFormat != OMX_COLOR_Format24bitRGB888
- || mColorFormat != OMX_COLOR_Format32bitARGB8888)))
- mColorFormat = OMX_COLOR_Format32bitARGB8888;
-
- pthread_attr_t attr;
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
- pthread_create(&mThread, &attr, ThreadWrapper, this);
- pthread_attr_destroy(&attr);
-
- mStart = true;
-
- ALOGV("[%s %d]", __FUNCTION__, __LINE__);
- return OK;
- }
-
- status_t ScreenCatch::stop()
- {
- ALOGV("[%s %d]", __FUNCTION__, __LINE__);
- Mutex::Autolock autoLock(mLock);
- mStart = false;
-
- mThreadOutCondition.waitRelative(mLock, 1000000000000);
- ALOGV("[%s %d]", __FUNCTION__, __LINE__);
-
- while (!mRawBufferQueue.empty()) {
-
- ALOGV("[%s %d] free buffer", __FUNCTION__, __LINE__);
-
- MediaBuffer *rawBuffer = *mRawBufferQueue.begin();
- mRawBufferQueue.erase(mRawBufferQueue.begin());
- rawBuffer->release();
- }
-
- mScreenMediaSourceService->stop(mClientId);
- mScreenMediaSourceService->unregisterClient(mClientId);
-
- return OK;
- }
-
- status_t ScreenCatch::read(MediaBuffer **buffer)
- {
- Mutex::Autolock autoLock(mLock);
-
- if (!mRawBufferQueue.empty()) {
- MediaBuffer *rawBuffer = *mRawBufferQueue.begin();
- mRawBufferQueue.erase(mRawBufferQueue.begin());
- *buffer = rawBuffer;
- return OK;
- }
-
- return !OK;
- }
-
- status_t ScreenCatch::free(MediaBuffer *buffer)
- {
- Mutex::Autolock autoLock(mLock);
- buffer->release();
- return OK;
- }
+ struct ScreenCatch::ScreenCatchClient : public BnScreenMediaSourceClient {
+ ScreenCatchClient(void *user)
+ {
+ mUser = user;
+ ALOGE("[%s %d] user:%x", __FUNCTION__, __LINE__, user);
+ }
+
+ virtual void notify(int msg, int ext1, int ext2, const Parcel *obj)
+ {
+ ALOGI("notify %d, %d, %d", msg, ext1, ext2);
+ }
+
+ virtual int dataCallback(const sp<IMemory> &data)
+ {
+ return 0;
+ }
+
+ protected:
+ void *mUser;
+ virtual ~ScreenCatchClient() {}
+
+ private:
+ DISALLOW_EVIL_CONSTRUCTORS(ScreenCatchClient);
+ };
+
+ ScreenCatch::ScreenCatch(uint32_t bufferWidth, uint32_t bufferHeight, uint32_t bitSize) :
+ mWidth(ALIGN(bufferWidth)),
+ mHeight(bufferHeight),
+ mScreenMediaSourceService(NULL),
+ mColorFormat(OMX_COLOR_Format32bitARGB8888),
+ mBitSize(bitSize)
+ {
+ ALOGE("ScreenCatch: %dx%d", bufferWidth, bufferHeight);
+
+ if (bufferWidth <= 0 || bufferHeight <= 0 || bufferWidth > 1920 || bufferHeight > 1080) {
+ ALOGE("Invalid dimensions %dx%d", bufferWidth, bufferHeight);
+ }
+
+ if (bitSize != 24 || bitSize != 32)
+ bitSize = 32;
+
+ mCorpX = -1;
+ mCorpY = -1;
+ mCorpWidth = -1;
+ mCorpHeight = -1;
+
+ }
+
+ ScreenCatch::~ScreenCatch()
+ {
+ ALOGE("~ScreenCatch");
+ }
+
+ void ScreenCatch::setVideoRotation(int degree)
+ {
+ int angle;
+
+ ALOGI("[%s %d] setVideoRotation degree:%x", __FUNCTION__, __LINE__, degree);
+
+ }
+
+ void ScreenCatch::setVideoCrop(int x, int y, int width, int height)
+ {
+ mCorpX = x;
+ mCorpY = y;
+ mCorpWidth = width;
+ mCorpHeight = height;
+ }
+
+ static inline void yuv_to_rgb32(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb)
+ {
+ register int r, g, b;
+
+ r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10;
+ g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u - 128) ) >> 10;
+ b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10;
+
+ r = r > 255 ? 255 : r < 0 ? 0 : r;
+ g = g > 255 ? 255 : g < 0 ? 0 : g;
+ b = b > 255 ? 255 : b < 0 ? 0 : b;
+
+ /*ARGB*/
+ *rgb = (unsigned char)r;
+ rgb++;
+ *rgb = (unsigned char)g;
+ rgb++;
+ *rgb = (unsigned char)b;
+ rgb++;
+ *rgb = 0xff;
+
+ }
+
+ void nv21_to_rgb32(unsigned char *buf, unsigned char *rgb, int width, int height)
+ {
+ int x, y, z = 0;
+ int h, w;
+ int blocks;
+ unsigned char Y1, Y2, U, V;
+
+ blocks = (width * height) * 2;
+
+ for (h = 0, z = 0; h < height; h += 2) {
+ for (y = 0; y < width * 2; y += 2) {
+
+ Y1 = buf[ h * width + y + 0];
+ V = buf[ blocks / 2 + h * width / 2 + y % width + 0 ];
+ Y2 = buf[ h * width + y + 1];
+ U = buf[ blocks / 2 + h * width / 2 + y % width + 1 ];
+
+ yuv_to_rgb32(Y1, U, V, &rgb[z]);
+ yuv_to_rgb32(Y2, U, V, &rgb[z + 4]);
+ z += 8;
+ }
+ }
+ }
+
+ static inline void yuv_to_rgb24(unsigned char y, unsigned char u, unsigned char v, unsigned char *rgb)
+ {
+ register int r, g, b;
+
+ r = (1192 * (y - 16) + 1634 * (v - 128) ) >> 10;
+ g = (1192 * (y - 16) - 833 * (v - 128) - 400 * (u - 128) ) >> 10;
+ b = (1192 * (y - 16) + 2066 * (u - 128) ) >> 10;
+
+ r = r > 255 ? 255 : r < 0 ? 0 : r;
+ g = g > 255 ? 255 : g < 0 ? 0 : g;
+ b = b > 255 ? 255 : b < 0 ? 0 : b;
+
+ /*ARGB*/
+ *rgb = (unsigned char)r;
+ rgb++;
+ *rgb = (unsigned char)g;
+ rgb++;
+ *rgb = (unsigned char)b;
+ }
+
+ void nv21_to_rgb24(unsigned char *buf, unsigned char *rgb, int width, int height)
+ {
+ int x, y, z = 0;
+ int h, w;
+ int blocks;
+ unsigned char Y1, Y2, U, V;
+
+ blocks = (width * height) * 2;
+
+ for (h = 0, z = 0; h < height; h += 2) {
+ for (y = 0; y < width * 2; y += 2) {
+
+ Y1 = buf[ h * width + y + 0];
+ V = buf[ blocks / 2 + h * width / 2 + y % width + 0 ];
+ Y2 = buf[ h * width + y + 1];
+ U = buf[ blocks / 2 + h * width / 2 + y % width + 1 ];
+
+ yuv_to_rgb24(Y1, U, V, &rgb[z]);
+ yuv_to_rgb24(Y2, U, V, &rgb[z + 3]);
+ z += 6;
+ }
+ }
+ }
+
+ int ScreenCatch::threadFunc()
+ {
+ int64_t pts;
+ int status;
+
+ sp<MemoryHeapBase> newMemoryHeap = new MemoryHeapBase(mWidth * mHeight * 3 / 2);
+ sp<MemoryBase> buffer = new MemoryBase(newMemoryHeap, 0, mWidth * mHeight * 3 / 2);
+
+ ALOGV("[%s %d] empty:%d", __FUNCTION__, __LINE__, mRawBufferQueue.empty());
+
+ while (mStart == true) {
+
+ status = mScreenMediaSourceService->readBuffer(mClientId, buffer, &pts);
+
+ if (status != OK && mStart == true) {
+ usleep(10000);
+ continue;
+ }
+
+ if (mStart != true)
+ break;
+
+ MediaBuffer *accessUnit;
+
+ if (OMX_COLOR_Format24bitRGB888 == mColorFormat) { //rgb 24bit
+ accessUnit = new MediaBuffer(mWidth * mHeight * 3);
+ nv21_to_rgb24((unsigned char *)buffer->pointer(), (unsigned char *)accessUnit->data(), mWidth, mHeight);
+ accessUnit->set_range(0, mWidth * mHeight * 3);
+ } else if (OMX_COLOR_Format32bitARGB8888 == mColorFormat) { //rgba 32bit
+ accessUnit = new MediaBuffer(mWidth * mHeight * 4);
+ nv21_to_rgb32((unsigned char *)buffer->pointer(), (unsigned char *)accessUnit->data(), mWidth, mHeight);
+ accessUnit->set_range(0, mWidth * mHeight * 4);
+ } else if (OMX_COLOR_FormatYUV420SemiPlanar == mColorFormat) { //nv21
+ accessUnit = new MediaBuffer(mWidth * mHeight * 3 / 2);
+ memcpy((unsigned char *)accessUnit->data(), (unsigned char *)buffer->pointer(), mWidth * mHeight * 3 / 2);
+ accessUnit->set_range(0, mWidth * mHeight * 3 / 2);
+ }
+ mRawBufferQueue.push_back(accessUnit);
+ }
+
+ ALOGE("[%s %d] thread out", __FUNCTION__, __LINE__);
+
+ mThreadOutCondition.signal();
+
+ return 0;
+ }
+
+ void *ScreenCatch::ThreadWrapper(void *me)
+ {
+
+ ScreenCatch *Convertor = static_cast<ScreenCatch *>(me);
+ Convertor->threadFunc();
+ return NULL;
+ }
+
+ status_t ScreenCatch::start(MetaData *params)
+ {
+ ALOGE("[%s %d] mWidth:%d mHeight:%d", __FUNCTION__, __LINE__, mWidth, mHeight);
+ Mutex::Autolock autoLock(mLock);
+
+ status_t status;
+ int64_t pts;
+ int client_id;
+
+ sp<IServiceManager> sm = defaultServiceManager();
+ sp<IBinder> binder = sm->getService(String16("media.screenmediasource"));
+ mScreenMediaSourceService = interface_cast<IScreenMediaSource>(binder);
+
+ sp<ScreenCatchClient> mIScreenSourceClient = new ScreenCatchClient(this);
+
+ ALOGE("[%s %d] mWidth:%d mHeight:%d", __FUNCTION__, __LINE__, mWidth, mHeight);
+
+ mScreenMediaSourceService->registerClient(mIScreenSourceClient, mWidth, mHeight, 1, SCREENMEDIASOURC_RAWDATA_TYPE, &client_id, NULL);
+
+ ALOGE("[%s %d] client_id:%d", __FUNCTION__, __LINE__, client_id);
+
+ mClientId = client_id;
+
+ if (status != OK) {
+ ALOGE("setResolutionRatio fail");
+ return !OK;
+ }
+
+ ALOGV("[%s %d] mCorpX:%d mCorpY:%d mCorpWidth:%d mCorpHeight:%d", __FUNCTION__, __LINE__, mCorpX, mCorpY, mCorpWidth, mCorpHeight);
+
+ if (mCorpX != -1)
+ mScreenMediaSourceService->setVideoCrop(client_id, mCorpX, mCorpY, mCorpWidth, mCorpHeight);
+
+
+ status = mScreenMediaSourceService->start(client_id);
+
+ if (status != OK) {
+ mScreenMediaSourceService->unregisterClient(mClientId);
+ ALOGE("ScreenMediaSourceService start fail");
+ return !OK;
+ }
+
+ if (!(params->findInt32(kKeyColorFormat, &mColorFormat)
+ && (mColorFormat != OMX_COLOR_FormatYUV420SemiPlanar
+ || mColorFormat != OMX_COLOR_Format24bitRGB888
+ || mColorFormat != OMX_COLOR_Format32bitARGB8888)))
+ mColorFormat = OMX_COLOR_Format32bitARGB8888;
+
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
+ pthread_create(&mThread, &attr, ThreadWrapper, this);
+ pthread_attr_destroy(&attr);
+
+ mStart = true;
+
+ ALOGV("[%s %d]", __FUNCTION__, __LINE__);
+ return OK;
+ }
+
+ status_t ScreenCatch::stop()
+ {
+ ALOGV("[%s %d]", __FUNCTION__, __LINE__);
+ Mutex::Autolock autoLock(mLock);
+ mStart = false;
+
+ mThreadOutCondition.waitRelative(mLock, 1000000000000);
+ ALOGV("[%s %d]", __FUNCTION__, __LINE__);
+
+ while (!mRawBufferQueue.empty()) {
+
+ ALOGV("[%s %d] free buffer", __FUNCTION__, __LINE__);
+
+ MediaBuffer *rawBuffer = *mRawBufferQueue.begin();
+ mRawBufferQueue.erase(mRawBufferQueue.begin());
+ rawBuffer->release();
+ }
+
+ mScreenMediaSourceService->stop(mClientId);
+ mScreenMediaSourceService->unregisterClient(mClientId);
+
+ return OK;
+ }
+
+ status_t ScreenCatch::read(MediaBuffer **buffer)
+ {
+ Mutex::Autolock autoLock(mLock);
+
+ if (!mRawBufferQueue.empty()) {
+ MediaBuffer *rawBuffer = *mRawBufferQueue.begin();
+ mRawBufferQueue.erase(mRawBufferQueue.begin());
+ *buffer = rawBuffer;
+ return OK;
+ }
+
+ return !OK;
+ }
+
+ status_t ScreenCatch::free(MediaBuffer *buffer)
+ {
+ Mutex::Autolock autoLock(mLock);
+ buffer->release();
+ return OK;
+ }
} // end of namespace android