Skip to content

Commit 3a6c96e

Browse files
committed
add thread class
1 parent bb8d6b6 commit 3a6c96e

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

jni/libmediaplayer/Android.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ LOCAL_SRC_FILES += \
1414
decoder.cpp \
1515
decoder_audio.cpp \
1616
decoder_video.cpp \
17+
thread.cpp \
1718
renderer.cpp
1819

1920
LOCAL_LDLIBS := -llog

jni/libmediaplayer/thread.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#include <android/log.h>
2+
#include "thread.h"
3+
4+
#define TAG "FFMpegThread"
5+
6+
void Thread::start()
7+
{
8+
handleRun(NULL);
9+
}
10+
11+
void Thread::startAsync()
12+
{
13+
pthread_create(&mThread, NULL, startThread, this);
14+
}
15+
16+
int Thread::wait()
17+
{
18+
return pthread_join(mThread, NULL);
19+
}
20+
21+
void Thread::stop()
22+
{
23+
}
24+
25+
void* Thread::startThread(void* ptr)
26+
{
27+
__android_log_print(ANDROID_LOG_INFO, TAG, "starting thread");
28+
Thread* thread = (Thread *) ptr;
29+
thread->mRunning = true;
30+
thread->handleRun(ptr);
31+
thread->mRunning = false;
32+
__android_log_print(ANDROID_LOG_INFO, TAG, "thread ended");
33+
}
34+
35+
void Thread::handleRun(void* ptr)
36+
{
37+
}

jni/libmediaplayer/thread.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#ifndef FFMPEG_THREAD_H
2+
#define FFMPEG_THREAD_H
3+
4+
#include <pthread.h>
5+
6+
class Thread
7+
{
8+
public:
9+
Thread();
10+
~Thread();
11+
12+
void start();
13+
void startAsync();
14+
int wait();
15+
virtual void stop();
16+
17+
protected:
18+
pthread_t mThread;
19+
bool mRunning;
20+
21+
virtual void handleRun(void* ptr);
22+
23+
private:
24+
static void* startThread(void* ptr);
25+
};
26+
27+
#endif //FFMPEG_DECODER_H

0 commit comments

Comments
 (0)