1
0
mirror of https://github.com/ioacademy-jikim/multimedia synced 2026-08-11 16:33:04 +00:00

멀티미디어 예제

This commit is contained in:
ioacademy-jikim
2015-08-04 19:14:13 +09:00
commit d3b375295e
59 changed files with 8232 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= test-bitmap.cpp
LOCAL_SHARED_LIBRARIES := libutils libgui libui
LOCAL_MODULE:= test-bitmap
LOCAL_CFLAGS:= -g -O0
LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
Binary file not shown.

After

Width:  |  Height:  |  Size: 145 KiB

+133
View File
@@ -0,0 +1,133 @@
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <ui/PixelFormat.h>
#include <media/mediaplayer.h>
#include <media/IMediaPlayer.h>
#include <binder/ProcessState.h>
#include <binder/IPCThreadState.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h>
#include <utils/String8.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <utils/RefBase.h>
#include <utils/StrongPointer.h>
#include <gui/Surface.h>
using namespace android;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
struct BITMAPFILEHEADER {
u16 bfType;
u32 bfSize;
u16 bfReserved1;
u16 bfReserved2;
u32 bfOffBits;
} __attribute((packed));
struct BITMAPINFOHEADER {
u32 biSize;
u32 biWidth;
u32 biHeight;
u16 biPlanes;
u16 biBitCount;
u32 biCompression;
u32 biSizeImage;
u32 biXPelsPerMeter;
u32 biYPelsPerMeter;
u32 biClrUsed;
u32 biClrImportant;
} __attribute((packed));
void fillRGBA8BMP(uint8_t* dst, uint8_t* src, int w, int h, int stride, int bpp)
{
const size_t PIXEL_SIZE = 4;
src = src+w*h*bpp;
for (int y = 0; y < h; y++) {
src -= w*bpp;
for (int x = 0; x < w; x++) {
off_t offset = (y * stride + x) * PIXEL_SIZE;
dst[offset + 0] = src[x*bpp+2];
dst[offset + 1] = src[x*bpp+1];
dst[offset + 2] = src[x*bpp+0];
dst[offset + 3] = 255;
}
}
}
int main()
{
int fd;
int w,h;
BITMAPFILEHEADER file_header;
BITMAPINFOHEADER DIB;
fd = open("bbb.bmp", O_RDONLY);
printf("fd=%d\n", fd );
read( fd, &file_header, sizeof file_header );
read( fd, &DIB, sizeof DIB );
w = DIB.biWidth;
h = DIB.biHeight;
printf("size=%u\n", file_header.bfSize );
printf("BitCount=%u\n", DIB.biBitCount );
int bpp = DIB.biBitCount/8;
uint8_t *src = (uint8_t*)malloc( DIB.biSizeImage*bpp );
read( fd, src, DIB.biSizeImage*bpp );
sp <Surface> gsf;
status_t nState;
printf("create SurfaceComposerClient\n");
sp<SurfaceComposerClient> composerClient;
sp<SurfaceControl> control;
composerClient = new SurfaceComposerClient;
composerClient->initCheck();
printf("create video surface\n");
control = composerClient->createSurface(
String8("A Surface"),
w,
h,
PIXEL_FORMAT_RGBA_8888,
0);
SurfaceComposerClient::openGlobalTransaction();
control->setLayer(INT_MAX);
control->show();
SurfaceComposerClient::closeGlobalTransaction();
sp<ANativeWindow> window;
window = control->getSurface();
ANativeWindowBuffer *anb;
native_window_dequeue_buffer_and_wait(window.get(), &anb);
sp<GraphicBuffer> buf(new GraphicBuffer(anb, false));
uint8_t* img = NULL;
buf->lock(GRALLOC_USAGE_SW_WRITE_OFTEN, (void**)(&img));
printf("width=%d, height=%d, stride=%d\n",
buf->getWidth(), buf->getHeight(), buf->getStride());
fillRGBA8BMP(img, src, w, h, buf->getStride(), bpp);
buf->unlock();
window->queueBuffer(window.get(), buf->getNativeBuffer(), -1);
getchar();
free(src);
close(fd);
}
+9
View File
@@ -0,0 +1,9 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SHARED_LIBRARIES := liblog libutils libmedia
LOCAL_SRC_FILES := my_looper.cpp
LOCAL_MODULE := my_looper
include $(BUILD_EXECUTABLE)
+263
View File
@@ -0,0 +1,263 @@
#if 1
#include <stdio.h>
#include <utils/Looper.h>
#include <utils/StrongPointer.h>
using namespace android;
class MyThread : public Thread {
sp<Looper> mLooper;
sp<MessageHandler> mHandler;
public :
MyThread( sp<Looper> &looper , sp<MessageHandler> &handler )
: mLooper(looper),mHandler(handler){}
bool threadLoop() {
mLooper->sendMessageDelayed( s2ns(3), mHandler, Message(3) );
return false;
}
};
class MyMessageHandler : public MessageHandler
{
public:
virtual void handleMessage(const Message& message)
{
printf("MyMessageHandler::handleMessage(%d)\n", message.what );
}
};
int main()
{
int ret;
sp<Looper> looper = new Looper(true);
sp<MessageHandler> handler = new MyMessageHandler;
sp<Thread> thread = new MyThread( looper, handler );
thread->run();
while( 1)
{
ret = looper->pollOnce(-1);
if( ret == Looper::POLL_WAKE )
printf("Looper::POLL_WAKE\n");
if( ret == Looper::POLL_CALLBACK )
printf("Looper::POLL_CALLBACK\n");
}
return 0;
}
#endif
#if 0
#include <stdio.h>
#include <utils/Looper.h>
#include <utils/StrongPointer.h>
using namespace android;
class MyThread : public Thread {
sp<Looper> mLooper;
int mFd;
public :
MyThread( sp<Looper> &looper , int fd ) : mLooper(looper),mFd(fd){}
bool threadLoop() {
sleep(3);
write( mFd, "W", 1 );
return false;
}
};
class CallbackHandler
{
public:
void setCallback( sp<Looper> &looper, int fd, int events )
{
looper->addFd( fd, 0, events, callbackFunc, this );
}
static int callbackFunc(int fd, int events, void* data)
{
return ((CallbackHandler*)data)->handler( fd, events, data );
}
virtual ~CallbackHandler(){}
virtual int handler(int fd, int events, void* data) = 0;
};
class MyCallback : public CallbackHandler
{
public:
int handler(int fd, int events, void* data)
{
printf("MyCallback::handler(%d, %d, %p)\n", fd, events, data);
return 0;
}
};
int main()
{
int ret;
int fds[2];
pipe(fds);
MyCallback callback;
sp<Looper> looper = new Looper(true);
sp<Thread> thread = new MyThread( looper, fds[1] );
callback.setCallback( looper, fds[0], Looper::EVENT_INPUT );
thread->run();
while( 1)
{
ret = looper->pollOnce(-1);
if( ret == Looper::POLL_WAKE )
printf("Looper::POLL_WAKE\n");
if( ret == Looper::POLL_CALLBACK )
printf("Looper::POLL_CALLBACK\n");
}
return 0;
}
#endif
#if 0
#include <stdio.h>
#include <utils/Looper.h>
#include <utils/StrongPointer.h>
using namespace android;
class MyThread : public Thread {
sp<Looper> mLooper;
int mFd;
public :
MyThread( sp<Looper> &looper , int fd ) : mLooper(looper),mFd(fd){}
bool threadLoop() {
sleep(3);
write( mFd, "W", 1 );
return false;
}
};
class MyCallback
{
public:
void setCallback( sp<Looper> &looper, int fd, int events )
{
looper->addFd( fd, 0, events, callbackFunc, this );
}
static int callbackFunc(int fd, int events, void* data)
{
return ((MyCallback*)data)->handler( fd, events, data );
}
int handler(int fd, int events, void* data)
{
printf("MyCallback::handler(%d, %d, %p)\n", fd, events, data);
return 0;
}
};
int main()
{
int ret;
int fds[2];
pipe(fds);
MyCallback callback;
sp<Looper> looper = new Looper(true);
sp<Thread> thread = new MyThread( looper, fds[1] );
callback.setCallback( looper, fds[0], Looper::EVENT_INPUT );
thread->run();
while( 1)
{
ret = looper->pollOnce(-1);
if( ret == Looper::POLL_WAKE )
printf("Looper::POLL_WAKE\n");
if( ret == Looper::POLL_CALLBACK )
printf("Looper::POLL_CALLBACK\n");
}
return 0;
}
#endif
#if 0
#include <stdio.h>
#include <utils/Looper.h>
#include <utils/StrongPointer.h>
using namespace android;
class MyThread : public Thread {
sp<Looper> mLooper;
int mFd;
public :
MyThread( sp<Looper> &looper , int fd ) : mLooper(looper),mFd(fd){}
bool threadLoop() {
sleep(3);
write( mFd, "W", 1 );
return false;
}
};
int foo(int fd, int events, void* data)
{
printf("foo(%d, %d, %p)\n", fd, events, data);
return 0;
}
int main()
{
int ret;
int fds[2];
pipe(fds);
sp<Looper> looper = new Looper(true);
sp<Thread> thread = new MyThread( looper, fds[1] );
looper->addFd( fds[0], Looper::POLL_CALLBACK, Looper::EVENT_INPUT, foo, 0 );
thread->run();
while( 1)
{
ret = looper->pollOnce(-1);
if( ret == Looper::POLL_WAKE )
printf("Looper::POLL_WAKE\n");
if( ret == Looper::POLL_CALLBACK )
printf("Looper::POLL_CALLBACK\n");
}
return 0;
}
#endif
#if 0
#include <stdio.h>
#include <utils/Looper.h>
#include <utils/StrongPointer.h>
using namespace android;
class MyThread : public Thread {
sp<Looper> mLooper;
public :
MyThread( sp<Looper> &looper ) : mLooper(looper){}
bool threadLoop() {
sleep(3);
mLooper->wake();
return false;
}
};
int main()
{
int ret;
sp<Looper> looper = new Looper(true);
sp<Thread> thread = new MyThread( looper );
thread->run();
while( 1)
{
ret = looper->pollOnce(-1);
if( ret == Looper::POLL_WAKE )
printf("Looper::POLL_WAKE\n");
}
return 0;
}
#endif
+18
View File
@@ -0,0 +1,18 @@
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= \
vsync.cpp
LOCAL_SHARED_LIBRARIES := \
libcutils \
libutils \
libbinder \
libui \
libgui
LOCAL_MODULE:= test-vsync-events
LOCAL_MODULE_TAGS := tests
include $(BUILD_EXECUTABLE)
+68
View File
@@ -0,0 +1,68 @@
#include <gui/DisplayEventReceiver.h>
#include <utils/Looper.h>
#include <android/looper.h>
using namespace android;
int receiver(int fd, int events, void* data)
{
DisplayEventReceiver* q = (DisplayEventReceiver*)data;
ssize_t n;
DisplayEventReceiver::Event buffer[1];
static nsecs_t oldTimeStamp = 0;
while ((n = q->getEvents(buffer, 1)) > 0) {
for (int i=0 ; i<n ; i++) {
if (buffer[i].header.type == DisplayEventReceiver::DISPLAY_EVENT_VSYNC) {
printf("event vsync: count=%d\t", buffer[i].vsync.count);
}
if (oldTimeStamp) {
float t = float(buffer[i].header.timestamp - oldTimeStamp) / s2ns(1);
printf("%f ms (%f Hz)\n", t*1000, 1.0/t);
}
oldTimeStamp = buffer[i].header.timestamp;
}
}
if (n<0) {
printf("error reading events (%s)\n", strerror(-n));
}
return 1;
}
int main(int argc, char** argv)
{
DisplayEventReceiver myDisplayEvent;
sp<Looper> loop = new Looper(false);
loop->addFd(myDisplayEvent.getFd(), 0, ALOOPER_EVENT_INPUT, receiver,
&myDisplayEvent);
myDisplayEvent.setVsyncRate(1);
do {
//printf("about to poll...\n");
int32_t ret = loop->pollOnce(-1);
switch (ret) {
case ALOOPER_POLL_WAKE:
//("ALOOPER_POLL_WAKE\n");
break;
case ALOOPER_POLL_CALLBACK:
//("ALOOPER_POLL_CALLBACK\n");
break;
case ALOOPER_POLL_TIMEOUT:
printf("ALOOPER_POLL_TIMEOUT\n");
break;
case ALOOPER_POLL_ERROR:
printf("ALOOPER_POLL_TIMEOUT\n");
break;
default:
printf("ugh? poll returned %d\n", ret);
break;
}
} while (1);
return 0;
}