Skip to content

Commit

Permalink
feat:asynchronous thread, now we have a message-looper-hander(Referen…
Browse files Browse the repository at this point in the history
…ce from Android)

添加了个新功能,现在支持异步线程,我们有了一个支持同步/异步 message+looper+hander的机制。(从android framwork 中的 AHander ALooper AMessage 借鉴而来,不过我们用了c++11/c++17 stl库进行了重新实现)
  • Loading branch information
xiancan committed Aug 1, 2022
1 parent 3c098b3 commit 74ae413
Show file tree
Hide file tree
Showing 15 changed files with 1,563 additions and 3 deletions.
1 change: 1 addition & 0 deletions clientAndroid/live555/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions clientAndroid/live555/app/src/main/jni/Android.mk
Expand Up @@ -39,6 +39,30 @@ LOCAL_EXPORT_C_INCLUDES := $(MY_ABSULATION_DIR)/include \
include $(PREBUILT_SHARED_LIBRARY)



include $(CLEAR_VARS)
LOCAL_MODULE := libbase
LOCAL_SRC_FILES := base/CMessage.cpp
LOCAL_SRC_FILES += base/CHandler.cpp
LOCAL_SRC_FILES += base/CLooper.cpp
LOCAL_SRC_FILES += base/CLooperRoster.cpp
LOCAL_CPP_FEATURES := rtti
LOCAL_APP_STL := c++_shared
LOCAL_CFLAGS += -Wall -Werror
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE := baseTest
LOCAL_SRC_FILES := base/test/LooperTest.cpp
LOCAL_CFLAGS += -Wall -Werror
LOCAL_LDLIBS := -llog -landroid
LOCAL_STATIC_LIBRARIES := libbase
include $(BUILD_EXECUTABLE)
#include $(BUILD_STATIC_LIBRARY)
#include $(BUILD_SHARED_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE := live555player
LOCAL_SRC_FILES := live555player_jni.cpp
Expand All @@ -53,6 +77,7 @@ LOCAL_SRC_FILES += MediaQueue.cpp
LOCAL_SRC_FILES += Render/OboeRender.cpp
LOCAL_CFLAGS += -DNO_OPENSSL=1 -Wall -Werror
LOCAL_STATIC_LIBRARIES := live_liveMedia live_groupsock live_UsageEnvironment live_BasicUsageEnvironment
#LOCAL_STATIC_LIBRARIES += baseTest
LOCAL_SHARED_LIBRARIES := liboboe
#LOCAL_LDLIBS := -lmediandk -llog -landroid -static-libstdc++ #报错,libstdc++.a 里面又有未定义的符号
#LOCAL_LDLIBS := -lmediandk -llog -landroid -static-libc++ #报错,不支持这个参数
Expand Down
5 changes: 4 additions & 1 deletion clientAndroid/live555/app/src/main/jni/Application.mk
@@ -1,8 +1,11 @@
APP_PLATFORM := android-21
#下面这个配置非常重要,不然由于c++库的问题,各种标准库链接符号问题。。。
#https://developer.android.google.cn/ndk/guides/cpp-support
APP_STL := c++_shared
APP_CPPFLAGS := -frtti -fexceptions
#APP_STL := c++_static

APP_ABI :=arm64-v8a
#APP_ABI +=armeabi
#APP_ABI +=armeabi-v7a
APP_CPPFLAGS += -Wno-error=format-security
APP_CPPFLAGS += -Wno-error=format-security -std=c++17
3 changes: 2 additions & 1 deletion clientAndroid/live555/app/src/main/jni/MediaQueue.h
Expand Up @@ -9,7 +9,8 @@
#include<queue>
#include<mutex>
#include "MediaBuffer.h"

// https://blog.csdn.net/qq_44443986/article/details/115864344
// 优先考虑 list,而不是queue queue非容器,而是容器适配器,对容器的一个包裹, 底层默认使用的是deque
class MediaQueue {
public:
MediaQueue(const std::string &codecName, size_t maxSize = 400);
Expand Down
10 changes: 10 additions & 0 deletions clientAndroid/live555/app/src/main/jni/base/CHandler.cpp
@@ -0,0 +1,10 @@
//
// Created by Administrator on 2022/7/31.
//

#include "CHandler.h"

void CHandler::deliverMessage(const std::shared_ptr<CMessage> &msg) {
onMessageReceived(msg);
mMessageCounter++;
}
60 changes: 60 additions & 0 deletions clientAndroid/live555/app/src/main/jni/base/CHandler.h
@@ -0,0 +1,60 @@
//
// Created by Administrator on 2022/7/31.
//

#ifndef LIVE555_CHANDLER_H
#define LIVE555_CHANDLER_H


#include <memory>
#include <map>
#include "CLooper.h"

class CMessage;

class CHandler :public std::enable_shared_from_this<CHandler> {
friend class CMessage; // deliverMessage()
friend class CLooperRoster; // clear()
public:
CLooper::handler_id id() const {
return mID;
}

std::shared_ptr<CLooper> looper() const {
return mLooper.lock();
}

std::weak_ptr<CLooper> getLooper() {
return mLooper;
}

std::weak_ptr<CHandler> getHandler() {
return shared_from_this();
}

protected:
virtual void onMessageReceived(const std::shared_ptr<CMessage> &msg) = 0;

private:

CLooper::handler_id mID = 0;
std::weak_ptr<CLooper> mLooper;

inline void setID(CLooper::handler_id id, const std::weak_ptr<CLooper> &looper) {
mID = id;
mLooper = looper;
}

inline void clear() {
mID = 0;
mLooper.reset();
}

uint32_t mMessageCounter = 0;
std::map<uint32_t, uint32_t> mMessages;

void deliverMessage(const std::shared_ptr<CMessage> &msg);
};


#endif //LIVE555_CHANDLER_H

0 comments on commit 74ae413

Please sign in to comment.