#define LOG_TAG "VideoCanvas" #include <android/api-level.h> #define LOG(...) ((void)0) #include "utils/log.h" #include <core/skCanvas.h> #include <core/SkPaint.h> #include <core/SkColor.h> #include <core/SkBitmap.h> #if __ANDROID_API__ >= 9 #include <surfaceflinger/Surface.h> #else #include <ui/Surface.h> #endif #include "media_VideoCanvas.h" using namespace android; static void* VideoLockCanvas(Surface* native_surface, int *width, int *height, int *stride) { Surface::SurfaceInfo info; void *canvasptr = NULL; status_t ret = 0; ret = native_surface->lock(&info); if (ret == OK) { canvasptr = info.bits; *width = info.w; *height = info.h; *stride = info.s; // LOGI("surface format %d", info.format); } return canvasptr; } static void VideoUnlockCanvas(Surface* native_surface) { native_surface->unlockAndPost(); } //sp<Surface> surfaceInstance; static Surface* previous_surface = NULL; void VideoCanvasSet(void *videocanvas){ Surface* native_surface = (Surface*)videocanvas; } void VideoCanvasDisplay(void *videocanvas, yuv2rgb_cb cb, void* cb_data){ Surface* native_surface = (Surface*)videocanvas; if(native_surface == NULL) { return; } LOGI("enter %p previous %p", native_surface, previous_surface); if(native_surface != previous_surface) { if(previous_surface != NULL) { previous_surface->decStrong((void*)VideoCanvasDisplay); //function name only as id } native_surface->incStrong((void*)VideoCanvasDisplay); previous_surface = native_surface; } int width, height, stride; void* bits = VideoLockCanvas(native_surface, &width, &height, &stride); if(bits == NULL) { return; } LOGI("lock %p width %d heigth %d stride %d", bits, width, height, stride); cb(cb_data, bits, width, height, stride); VideoUnlockCanvas(native_surface); LOGI("unlock"); } /* * The only purpose of class "MediaPlayer" is to call Surface::getISurface() * in frameworks/base/include/ui/Surface.h, which is private function and accessed * by friend class MediaPlayer. * * We define a fake one to cheat compiler */ /* namespace android { class MediaPlayer { public: static sp < ISurface > getSurface (const Surface * surface){ if(surface != NULL) { return surface->getISurface (); } return sp < ISurface >; }; }; }; */ void VideoCanvasClear(void *videocanvas){ Surface* native_surface = (Surface*)videocanvas; if(native_surface == NULL) { return; } LOGI("clear %p previous %p", native_surface, previous_surface); if(native_surface != previous_surface) { return; } int width, height, stride; void* bits = VideoLockCanvas(native_surface, &width, &height, &stride); if(bits == NULL) { return; } LOGI("clear lock %p width %d heigth %d stride %d", bits, width, height, stride); memset(bits, 0, stride*height*2); VideoUnlockCanvas(native_surface); LOGI("clear unlock"); } void VideoCanvasDestroy(void *videocanvas){ Surface* native_surface = (Surface*)videocanvas; //native_surface->clear(); } 仅供参考!
|
|