From b4c22313c0ba28bb4b4f4dad4f0a28c2161cf6d2 Mon Sep 17 00:00:00 2001 From: houxiao <houxiao@454eff88-639b-444f-9e54-f578c98de674> Date: 星期二, 28 二月 2017 14:36:00 +0800 Subject: [PATCH] add amcd --- RtspFace/main.cpp | 73 +++++--- RtspFace/live555/config.android | 13 + RtspFace/Logger/src/logger.hpp | 1 RtspFace/PL_H264Encoder.h | 1 RtspFace/PL_AVFrameBGRA.h | 15 + RtspFace/make.sh | 3 RtspFace/PL_H264Decoder.cpp | 1 RtspFace/PL_AndroidMediaCodecDecoder.cpp | 193 +++++++++++++++++++++ RtspFace/PL_H264Encoder.cpp | 9 RtspFace/logger.h | 12 RtspFace/Logger/src/logger.cc | 12 + RtspFace/live555/testProgs/testRTSPClient.hpp | 6 RtspFace/PL_AVFrameBGRA.cpp | 107 +++++++++-- RtspFace/PL_AndroidMediaCodecDecoder.h | 63 +++++++ 14 files changed, 445 insertions(+), 64 deletions(-) diff --git a/RtspFace/Logger/src/logger.cc b/RtspFace/Logger/src/logger.cc index 06748f2..c956b21 100644 --- a/RtspFace/Logger/src/logger.cc +++ b/RtspFace/Logger/src/logger.cc @@ -14,6 +14,11 @@ #include "logger.hpp" +#ifdef __ANDROID__ +#define LOG_TAG "logger" +#include <android/log.h> +#endif + Logger::Logger(std::ostream& s) : _file(), _log(s), _level(INFO), @@ -71,6 +76,11 @@ { if (_line_level >= _level) { _log << get_time() << " -- [" << level_str(_line_level) << "] -- " << str(); +#ifdef __ANDROID__ + std::stringstream& _log_ss(static_cast<std::stringstream&>(_log)); + __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, "%s", _log_ss.str().c_str());//#todo level convert + _log_ss.str(""); +#endif if (_file.is_open()) _log.flush(); } @@ -121,6 +131,8 @@ return ("DBG"); case INFO: return ("INF"); + case NOTICE: + return ("NOT"); case WARNING: return ("WRN"); case ERROR: diff --git a/RtspFace/Logger/src/logger.hpp b/RtspFace/Logger/src/logger.hpp index a39cea1..3c3eb14 100644 --- a/RtspFace/Logger/src/logger.hpp +++ b/RtspFace/Logger/src/logger.hpp @@ -27,6 +27,7 @@ VERBOSE = 0, DEBUG, INFO, + NOTICE, WARNING, ERROR, CRITICAL diff --git a/RtspFace/PL_AVFrameBGRA.cpp b/RtspFace/PL_AVFrameBGRA.cpp index 816a3db..addb967 100644 --- a/RtspFace/PL_AVFrameBGRA.cpp +++ b/RtspFace/PL_AVFrameBGRA.cpp @@ -20,9 +20,12 @@ bool payError; + PL_AVFrameBGRA_Config config; + PL_AVFrameBGRA_Internal() : buffSize(0), buffSizeMax(sizeof(buffer)), lastFrame(), - payError(true) + payError(true), + config() { } @@ -37,6 +40,9 @@ MB_Frame _lastFrame; lastFrame = _lastFrame; + + PL_AVFrameBGRA_Config _config; + config = _config; } }; @@ -59,6 +65,12 @@ { PL_AVFrameBGRA_Internal* in = (PL_AVFrameBGRA_Internal*)internal; in->reset(); + + if (args != nullptr) + { + PL_AVFrameBGRA_Config* _config = (PL_AVFrameBGRA_Config*)args; + in->config = *_config; + } return true; } @@ -84,46 +96,103 @@ if (pm.buffer == nullptr) return false; + int src_height = 0; + int src_width = 0; + const uint8* src_y = nullptr; + const uint8* src_u = nullptr; + const uint8* src_v = nullptr; + MB_Frame* frame = (MB_Frame*)pm.buffer; - if (frame->type != MB_Frame::MBFT_PTR_AVFRAME) + if (frame->type == MB_Frame::MBFT_PTR_AVFRAME) + { + AVFrame* pAVFrame = (AVFrame*)frame->buffer; + if (pAVFrame == nullptr) + return false; + + src_height = pAVFrame->height; + src_width = pAVFrame->width; + + src_y = pAVFrame->data[0]; + src_u = pAVFrame->data[1]; + src_v = pAVFrame->data[2]; + } + if (frame->type == MB_Frame::MBFT_YUV420) + { + if (frame->buffer == nullptr) + return false; + + src_height = frame->height; + src_width = frame->width; + + src_y = (const uint8*)(frame->buffer); + src_u = (const uint8*)(src_y + (src_height * src_width)); + src_v = (const uint8*)(src_u + (src_height * src_width / 4)); + } + else { LOG_ERROR << "Only support MBFT_PTR_AVFRAME" << std::endl; return false; } - AVFrame* pAVFrame = (AVFrame*)frame->buffer; - if (pAVFrame == nullptr) - return false; - - const int height = pAVFrame->height; - const int width = pAVFrame->width; - //int I420ToBGRA(const uint8* src_y, int src_stride_y, // const uint8* src_u, int src_stride_u, // const uint8* src_v, int src_stride_v, // uint8* dst_argb, int dst_stride_argb, -// int width, int height); +// int width, int src_height); - libyuv::I420ToBGRA(pAVFrame->data[0], width, - pAVFrame->data[1], SUBSAMPLE(width, 2), - pAVFrame->data[2], SUBSAMPLE(width, 2), - in->buffer, 4 * width, - width, height); + if (in->config.convertTo == PL_AVFrameBGRA_Config::I420_TO_BGRA8888) + { + libyuv::I420ToBGRA(src_y, src_width, + src_u, SUBSAMPLE(src_width, 2), + src_v, SUBSAMPLE(src_width, 2), + in->buffer, 4 * src_width, + src_width, src_height); - in->buffSize = in->buffSizeMax; + in->buffSize = src_width * src_height * 4; // #todo use ret value? + } + else if (in->config.convertTo == PL_AVFrameBGRA_Config::I420_TO_ARGB8888) + { + libyuv::I420ToARGB(src_y, src_width, + src_u, SUBSAMPLE(src_width, 2), + src_v, SUBSAMPLE(src_width, 2), + in->buffer, 4 * src_width, + src_width, src_height); + + in->buffSize = src_width * src_height * 4; // #todo use ret value? + } + else if (in->config.convertTo == PL_AVFrameBGRA_Config::I420_TO_ARGB8888) + { + libyuv::I420ToARGB(src_y, src_width, + src_u, SUBSAMPLE(src_width, 2), + src_v, SUBSAMPLE(src_width, 2), + in->buffer, 4 * src_width, + src_width, src_height); + + in->buffSize = src_width * src_height * 4; // #todo use ret value? + } + else if (in->config.convertTo == PL_AVFrameBGRA_Config::I420_TO_ARGB4444) + { + + } + else + { + LOG_ERROR << "PL_AVFrameBGRA_Config.convertTo not support" << std::endl; + return false; + } + //in->buffer readly in->lastFrame.type = MB_Frame::MBFT_BGRA; in->lastFrame.buffer = in->buffer; in->lastFrame.buffSize = in->buffSize; - in->lastFrame.width = width; - in->lastFrame.height = height; + in->lastFrame.width = src_width; + in->lastFrame.height = src_height; in->lastFrame.pts = frame->pts; //#test //static size_t f=0; //char fname[50]; - //sprintf(fname, "%u.bgra", ++f); + //sprintf(fname, "%u.argb", ++f); //FILE * pFile = fopen (fname,"wb"); //fwrite (in->buffer , sizeof(char), in->buffSize, pFile); //fclose(pFile); diff --git a/RtspFace/PL_AVFrameBGRA.h b/RtspFace/PL_AVFrameBGRA.h index 19c1381..ad130bd 100644 --- a/RtspFace/PL_AVFrameBGRA.h +++ b/RtspFace/PL_AVFrameBGRA.h @@ -3,6 +3,21 @@ #include "PipeLine.h" +struct PL_AVFrameBGRA_Config +{ + enum + { + I420_TO_BGRA8888, + I420_TO_ARGB8888, + I420_TO_ARGB4444, + I420_TO_RGB565 + } convertTo; + + PL_AVFrameBGRA_Config() : convertTo(I420_TO_BGRA8888) + { + } +}; + class PL_AVFrameBGRA : public PipeLineElem { public: diff --git a/RtspFace/PL_AndroidMediaCodecDecoder.cpp b/RtspFace/PL_AndroidMediaCodecDecoder.cpp new file mode 100644 index 0000000..23ed474 --- /dev/null +++ b/RtspFace/PL_AndroidMediaCodecDecoder.cpp @@ -0,0 +1,193 @@ +#include "PL_AndroidMediaCodecDecoder.h" +#include "MaterialBuffer.h" +#include "logger.h" + +struct PL_AMCD_Internal +{ + uint8_t buffer[1920*1080*4];//#todo from config + size_t buffSize; + size_t buffSizeMax; + MB_Frame lastFrame; + PL_AndroidMediaCodecDecoder_Config config; + + bool payError; + + AMediaCodec* codec; + + PL_AMCD_Internal() : + buffSize(0), buffSizeMax(sizeof(buffer)), lastFrame(), + config(), + payError(true), + codec(nullptr) + { + } + + ~PL_AMCD_Internal() + { + } + + void reset() + { + buffSize = 0; + payError = true; + + MB_Frame _lastFrame; + lastFrame = _lastFrame; + + PL_AndroidMediaCodecDecoder_Config _config; + config = _config; + + codec = nullptr; + } +}; + +PipeLineElem* create_PL_AndroidMediaCodecDecoder() +{ + return new PL_AndroidMediaCodecDecoder; +} + +PL_AndroidMediaCodecDecoder::PL_AndroidMediaCodecDecoder() : internal(new PL_AMCD_Internal) +{ +} + +PL_AndroidMediaCodecDecoder::~PL_AndroidMediaCodecDecoder() +{ + delete (PL_AMCD_Internal*)internal; + internal= nullptr; +} + +bool PL_AndroidMediaCodecDecoder::init(void* args) +{ + PL_AMCD_Internal* in = (PL_AMCD_Internal*)internal; + in->reset(); + + PL_AndroidMediaCodecDecoder_Config* config = (PL_AndroidMediaCodecDecoder_Config*)args; + in->config = *config; + + AMediaFormat* format = AMediaFormat_new(); + + AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, config.ak_mime.c_str()); + AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_HEIGHT, config.ak_height); + AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_WIDTH, config.ak_width); + + // should like: + // mime: string(video/avc), durationUs: int64(10000000), width: int32(480), height: int32(360), max-input-size: int32(55067), csd-0: data, csd-1: data} + LOG_INFO << "AMediaFormat_toString: " << AMediaFormat_toString(format) << LOG_ENDL; + + in->codec = AMediaCodec_createDecoderByType(config.ak_mime.c_str()); + if (AMediaCodec_configure(in->codec, format, data.window, NULL, 0) != AMEDIA_OK) + LOG_ERROR << "AMediaCodec_configure error" << LOG_ENDL; + + if (AMediaCodec_start(in->codec) != AMEDIA_OK) + LOG_ERROR << "AMediaCodec_start error" << LOG_ENDL; + + AMediaFormat_delete(format); + + return true; +} + +void PL_AndroidMediaCodecDecoder::finit() +{ + PL_AMCD_Internal* in = (PL_AMCD_Internal*)internal; + //todo release codec +} + +bool PL_AndroidMediaCodecDecoder::pay(const PipeMaterial& pm) +{ + PL_AMCD_Internal* in = (PL_AMCD_Internal*)internal; + + if (pm.type != PipeMaterial::PMT_FRAME) + { + LOG_ERROR << "Only support PMT_FRAME" << std::endl; + return false; + } + + if (pm.buffer == nullptr) + return false; + + MB_Frame* frame = (MB_Frame*)pm.buffer; + if (frame->type != MB_Frame::MBFT_H264_NALU) + { + LOG_ERROR << "Only support MBFT_H264_NALU" << std::endl; + return false; + } + + + + + ssize_t bufidx = AMediaCodec_dequeueInputBuffer(in->codec, 2000); + static int framecount = 0; + LOGP(DEBUG, "input buffer bufidx=%zd, framecount=%d", bufidx, framecount++); + + if (bufidx >= 0) + { + size_t bufsize; + uint8_t* buf = AMediaCodec_getInputBuffer(in->codec, bufidx, &bufsize); + size_t sampleSize = std::min(bufsize, frame->buffSize); + memcpy(buf, buffer, sampleSize); + //auto sampleSize = AMediaExtractor_readSampleData(d->ex, buf, bufsize); + //if (sampleSize < 0) { + // sampleSize = 0; + // d->sawInputEOS = true; + // LOGV("EOS"); + //} + //auto presentationTimeUs = AMediaExtractor_getSampleTime(d->ex); + uint64_t presentationTimeUs = presentationTime.tv_sec * 1000 * 1000 + presentationTime.tv_usec; //microseconds + + media_status_t ms = AMediaCodec_queueInputBuffer(data.codec, bufidx, 0, sampleSize, presentationTimeUs, 0); + //LOGV("media_status_t=%d", ms); + //AMediaExtractor_advance(d->ex); + } + + +// +// AVFrame* pAVFrame = (AVFrame*)frame->buffer; +// if (pAVFrame == nullptr) +// return false; +// +// const int height = pAVFrame->height; +// const int width = pAVFrame->width; +// +////int I420ToBGRA(const uint8* src_y, int src_stride_y, +//// const uint8* src_u, int src_stride_u, +//// const uint8* src_v, int src_stride_v, +//// uint8* dst_argb, int dst_stride_argb, +//// int width, int height); +// +// libyuv::I420ToBGRA(pAVFrame->data[0], width, +// pAVFrame->data[1], SUBSAMPLE(width, 2), +// pAVFrame->data[2], SUBSAMPLE(width, 2), +// in->buffer, 4 * width, +// width, height); +// +// in->buffSize = in->buffSizeMax; +// //in->buffer readly +// +// in->lastFrame.type = MB_Frame::MBFT_BGRA; +// in->lastFrame.buffer = in->buffer; +// in->lastFrame.buffSize = in->buffSize; +// in->lastFrame.width = width; +// in->lastFrame.height = height; +// in->lastFrame.pts = frame->pts; +// +// //#test +// //static size_t f=0; +// //char fname[50]; +// //sprintf(fname, "%u.bgra", ++f); +// //FILE * pFile = fopen (fname,"wb"); +// //fwrite (in->buffer , sizeof(char), in->buffSize, pFile); +// //fclose(pFile); +// + return true; +} + +bool PL_AndroidMediaCodecDecoder::gain(PipeMaterial& pm) +{ + PL_AMCD_Internal* in = (PL_AMCD_Internal*)internal; + + pm.type = PipeMaterial::PMT_FRAME; + pm.buffer = &(in->lastFrame); + pm.buffSize = 0; + pm.former = this; + return true; +} diff --git a/RtspFace/PL_AndroidMediaCodecDecoder.h b/RtspFace/PL_AndroidMediaCodecDecoder.h new file mode 100644 index 0000000..98ef7ee --- /dev/null +++ b/RtspFace/PL_AndroidMediaCodecDecoder.h @@ -0,0 +1,63 @@ +#ifndef _PL_ANDROIDMEDIACODECDECODER_H_ +#define _PL_ANDROIDMEDIACODECDECODER_H_ + +#include "PipeLine.h" + +struct PL_AndroidMediaCodecDecoder_Config +{ + // D:\adk\ndk-bundle\platforms\android-21\arch-arm64\usr\include\media\NdkMediaFormat.h + // AMEDIAFORMAT_KEY_AAC_PROFILE; + // AMEDIAFORMAT_KEY_BIT_RATE; + // AMEDIAFORMAT_KEY_CHANNEL_COUNT; + // AMEDIAFORMAT_KEY_CHANNEL_MASK; + // AMEDIAFORMAT_KEY_COLOR_FORMAT; + // AMEDIAFORMAT_KEY_DURATION; + // AMEDIAFORMAT_KEY_FLAC_COMPRESSION_LEVEL; + // AMEDIAFORMAT_KEY_FRAME_RATE; + uint32_t ak_height; // AMEDIAFORMAT_KEY_HEIGHT; + // AMEDIAFORMAT_KEY_IS_ADTS; + // AMEDIAFORMAT_KEY_IS_AUTOSELECT; + // AMEDIAFORMAT_KEY_IS_DEFAULT; + // AMEDIAFORMAT_KEY_IS_FORCED_SUBTITLE; + // AMEDIAFORMAT_KEY_I_FRAME_INTERVAL; + // AMEDIAFORMAT_KEY_LANGUAGE; + // AMEDIAFORMAT_KEY_MAX_HEIGHT; + // AMEDIAFORMAT_KEY_MAX_INPUT_SIZE; + // AMEDIAFORMAT_KEY_MAX_WIDTH; + std::string ak_mime; // AMEDIAFORMAT_KEY_MIME; // video/avc + // AMEDIAFORMAT_KEY_PUSH_BLANK_BUFFERS_ON_STOP; + // AMEDIAFORMAT_KEY_REPEAT_PREVIOUS_FRAME_AFTER; + // AMEDIAFORMAT_KEY_SAMPLE_RATE; + uint32_t ak_width; // AMEDIAFORMAT_KEY_WIDTH; + // AMEDIAFORMAT_KEY_STRIDE; + + void* windowSurface; + + PL_AndroidMediaCodecDecoder_Config() : + ak_height(0), + ak_mime(), + ak_width(0), + + windowSurface(nullptr) + {} +}; + +class PL_AndroidMediaCodecDecoder : public PipeLineElem +{ +public: + PL_AndroidMediaCodecDecoder(); + virtual ~PL_AndroidMediaCodecDecoder(); + + virtual bool init(void* args); + virtual void finit(); + + virtual bool pay(const PipeMaterial& pm); + virtual bool gain(PipeMaterial& pm); + +private: + void* internal; +}; + +PipeLineElem* create_PL_AndroidMediaCodecDecoder(); + +#endif diff --git a/RtspFace/PL_H264Decoder.cpp b/RtspFace/PL_H264Decoder.cpp index 0391e6a..87d8735 100644 --- a/RtspFace/PL_H264Decoder.cpp +++ b/RtspFace/PL_H264Decoder.cpp @@ -200,6 +200,7 @@ } else { + //#todo sps sps changing LOG_WARN << "incomplete frame" << std::endl; return false; } diff --git a/RtspFace/PL_H264Encoder.cpp b/RtspFace/PL_H264Encoder.cpp index 2af9e3e..68c502c 100644 --- a/RtspFace/PL_H264Encoder.cpp +++ b/RtspFace/PL_H264Encoder.cpp @@ -18,8 +18,8 @@ resetPTS(false), bytesBufferImageWidth(0), bytesBufferImageHeight(0), avc_bit_rate(1*1024*1024*8), //1Mbit - avc_fps(25), avc_gop(25), avc_max_b_frames(0), avc_profile(FF_PROFILE_H264_MAIN), - av_opt_preset("superfast"), av_opt_tune("") + avc_fps(25), avc_gop(25), avc_max_b_frames(0), avc_profile(FF_PROFILE_H264_BASELINE), + av_opt_preset("superfast"), av_opt_tune(""), avc_profile_str("") { // av_opt_tune: zerolatency } @@ -135,13 +135,16 @@ in->pAVCodecContext->time_base.den = in->config.avc_fps; in->pAVCodecContext->gop_size = in->config.avc_gop; in->pAVCodecContext->max_b_frames = in->config.avc_max_b_frames; - in->pAVCodecContext->profile = in->config.avc_profile; in->pAVCodecContext->pix_fmt = AV_PIX_FMT_YUV420P; if (!in->config.av_opt_preset.empty()) av_opt_set(in->pAVCodecContext->priv_data, "preset", in->config.av_opt_preset.c_str(), 0); if (!in->config.av_opt_tune.empty()) av_opt_set(in->pAVCodecContext->priv_data, "tune", in->config.av_opt_tune.c_str(), 0); + if (!in->config.avc_profile_str.empty()) + av_opt_set(in->pAVCodecContext->priv_data, "profile", in->config.avc_profile_str.c_str(), 0); + else + in->pAVCodecContext->profile = in->config.avc_profile; if(avcodec_open2(in->pAVCodecContext, avCodec, NULL) >= 0) { diff --git a/RtspFace/PL_H264Encoder.h b/RtspFace/PL_H264Encoder.h index e01f0af..c5c9c22 100644 --- a/RtspFace/PL_H264Encoder.h +++ b/RtspFace/PL_H264Encoder.h @@ -19,6 +19,7 @@ std::string av_opt_preset; std::string av_opt_tune; + std::string avc_profile_str; PL_H264Encoder_Config(); }; diff --git a/RtspFace/live555/config.android b/RtspFace/live555/config.android index cca14b6..49594dd 100644 --- a/RtspFace/live555/config.android +++ b/RtspFace/live555/config.android @@ -7,14 +7,21 @@ # $ make NDKROOT="$HOME/.local/share/android/android-ndk-r13b" TOOLCHAINPREFIX="$HOME/.local/share/android/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-" # ``` -# set ARCH, NDKLEVEL +# for ARM +# set ARCH = arm, NDKLEVEL = 23 # ./genMakefiles android # make NDKROOT="/opt/android-ndk-r13b" TOOLCHAINPREFIX="/opt/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-" clean # make NDKROOT="/opt/android-ndk-r13b" TOOLCHAINPREFIX="/opt/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-" # make NDKROOT="/opt/android-ndk-r13b" TOOLCHAINPREFIX="/opt/android-ndk-r13b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-" PREFIX="/opt/live.android/inst" install -ARCH = arm -NDKLEVEL = 22 +#for x86 +# ./genMakefiles android +# make NDKROOT="/opt/android-ndk-r13b" TOOLCHAINPREFIX="/opt/android-ndk-r13b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-" clean +# make NDKROOT="/opt/android-ndk-r13b" TOOLCHAINPREFIX="/opt/android-ndk-r13b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-" +# make NDKROOT="/opt/android-ndk-r13b" TOOLCHAINPREFIX="/opt/android-ndk-r13b/toolchains/x86-4.9/prebuilt/linux-x86_64/bin/i686-linux-android-" PREFIX="/opt/live.android/inst" install + +ARCH = x86 +NDKLEVEL = 23 ifeq ($(ARCH), arm) ifneq ($(APP_ABI), armeabi) CFLAGS += -march=armv7-a -mfloat-abi=softfp diff --git a/RtspFace/live555/testProgs/testRTSPClient.hpp b/RtspFace/live555/testProgs/testRTSPClient.hpp index f346165..75cc022 100644 --- a/RtspFace/live555/testProgs/testRTSPClient.hpp +++ b/RtspFace/live555/testProgs/testRTSPClient.hpp @@ -29,7 +29,7 @@ // By default, we request that the server stream its data using RTP/UDP. // If, instead, you want to request that the server stream via RTP-over-TCP, change the following to True: -#define REQUEST_STREAMING_OVER_TCP False +#define REQUEST_STREAMING_OVER_TCP True // Even though we're not going to be doing anything with the incoming data, we still need to receive it. // Define the size of the buffer that we'll use: @@ -62,13 +62,13 @@ void shutdownStream(RTSPClient* rtspClient, int exitCode = 1); // A function that outputs a string that identifies each stream (for debugging output). Modify this if you wish: -log4cpp::CategoryStream& operator<<(log4cpp::CategoryStream& logRoot, const RTSPClient& rtspClient) +Logger& operator<<(Logger& logRoot, const RTSPClient& rtspClient) { return logRoot << "[URL:\"" << rtspClient.url() << "\"]: "; } // A function that outputs a string that identifies each subsession (for debugging output). Modify this if you wish: -log4cpp::CategoryStream& operator<<(log4cpp::CategoryStream& logRoot, const MediaSubsession& subsession) +Logger& operator<<(Logger& logRoot, const MediaSubsession& subsession) { return logRoot << subsession.mediumName() << "/" << subsession.codecName(); } diff --git a/RtspFace/logger.h b/RtspFace/logger.h index d541876..63f4882 100644 --- a/RtspFace/logger.h +++ b/RtspFace/logger.h @@ -1,24 +1,22 @@ #ifndef LOGGER_H #define LOGGER_H -#include <Logger/src/logger.hpp> +#include "Logger/src/logger.hpp" #include <string.h> #include <unistd.h> -#ifndef LOG_TAG -#define LOG_TAG "logger" -#endif - extern Logger g_logger; -#define LOG(__level) g_logger << __level << __FILE__ << ":" << __LINE__ << "\t" +#define LOG(__level) g_logger << __level << __FILE__ << ":" << __LINE__ << "\t" #define LOGP(__level, __format, arg...) { char msg[1024]; sprintf(msg, "%s:%d\t" __format, __FILE__, __LINE__, ##arg); g_logger << __level << msg << std::endl; } #define LOG_DEBUG LOG(DEBUG) // Debug message do not care in any production environment #define LOG_INFO LOG(INFO) // Not significant event but useful for deal with online problem #define LOG_NOTICE LOG(NOTICE) // Important event -#define LOG_WARN LOG(WARN) // Important event or input which will lead to errors +#define LOG_WARN LOG(WARNING) // Important event or input which will lead to errors #define LOG_ERROR LOG(ERROR) // Error message means program running in an abnormal (not expected) way +#define LOG_ENDL std::endl + #endif diff --git a/RtspFace/main.cpp b/RtspFace/main.cpp index bbedf4d..0ab3414 100644 --- a/RtspFace/main.cpp +++ b/RtspFace/main.cpp @@ -14,8 +14,9 @@ #include "PL_DlibFaceTrack.h" #include "logger.h" +#include <iostream> -Logger g_logger(stdout); +Logger g_logger(std::cout); int main(int argc, char** argv) { @@ -27,6 +28,7 @@ PipeLine::register_global_elem_creator("PL_RTSPServer", create_PL_RTSPServer); PipeLine::register_global_elem_creator("PL_H264Decoder", create_PL_H264Decoder); PipeLine::register_global_elem_creator("PL_AVFrameYUV420", create_PL_AVFrameYUV420); + PipeLine::register_global_elem_creator("PL_AVFrameBGRA", create_PL_AVFrameBGRA); PipeLine::register_global_elem_creator("PL_H264Encoder", create_PL_H264Encoder); PipeLine::register_global_elem_creator("PL_Queue", create_PL_Queue); PipeLine::register_global_elem_creator("PL_Scale", create_PL_Scale); @@ -75,8 +77,8 @@ { PL_Scale_Config config; - config.toWidth = 800; - config.toHeight = 600; + config.toWidth = 480; + config.toHeight = 360; PL_Scale* ple = (PL_Scale*)pipeLine.push_elem("PL_Scale"); bool ret = ple->init(&config); if (!ret) @@ -85,13 +87,25 @@ exit(EXIT_FAILURE); } } - + { - SensetimeFaceTrackConfig config; - //config.generate_face_feature = true; - PL_SensetimeFaceTrack* ple = (PL_SensetimeFaceTrack*)pipeLine.push_elem("PL_SensetimeFaceTrack"); - ple->init(&config); + PL_AVFrameBGRA_Config config; + config.convertTo = PL_AVFrameBGRA_Config::I420_TO_ARGB8888; + PL_AVFrameBGRA* ple = (PL_AVFrameBGRA*)pipeLine.push_elem("PL_AVFrameBGRA"); + bool ret = ple->init(&config); + if (!ret) + { + LOG_ERROR << "PL_AVFrameBGRA.init error" << std::endl; + exit(EXIT_FAILURE); + } } + + //{ + // SensetimeFaceTrackConfig config; + // //config.generate_face_feature = true; + // PL_SensetimeFaceTrack* ple = (PL_SensetimeFaceTrack*)pipeLine.push_elem("PL_SensetimeFaceTrack"); + // ple->init(&config); + //} //PipeLine pipeLine2; //{ @@ -126,26 +140,29 @@ // } //} - { - PL_H264Encoder_Config config; - PL_H264Encoder* h264Encoder = (PL_H264Encoder*)pipeLine.push_elem("PL_H264Encoder"); - bool ret = h264Encoder->init(&config); - if (!ret) - { - LOG_ERROR << "PL_H264Encoder.init error" << std::endl; - exit(EXIT_FAILURE); - } - } - - { - PL_RTSPServer* rtspServer = (PL_RTSPServer*)pipeLine.push_elem("PL_RTSPServer"); - bool ret = rtspServer->init(nullptr); - if (!ret) - { - LOG_ERROR << "rtspServer.init error" << std::endl; - exit(EXIT_FAILURE); - } - } + //{ + // PL_H264Encoder_Config config; + // config.av_opt_preset = "superfast"; + // config.av_opt_tune = "zerolatency"; + // config.avc_profile_str = "baseline"; + // PL_H264Encoder* h264Encoder = (PL_H264Encoder*)pipeLine.push_elem("PL_H264Encoder"); + // bool ret = h264Encoder->init(&config); + // if (!ret) + // { + // LOG_ERROR << "PL_H264Encoder.init error" << std::endl; + // exit(EXIT_FAILURE); + // } + //} + // + //{ + // PL_RTSPServer* rtspServer = (PL_RTSPServer*)pipeLine.push_elem("PL_RTSPServer"); + // bool ret = rtspServer->init(nullptr); + // if (!ret) + // { + // LOG_ERROR << "rtspServer.init error" << std::endl; + // exit(EXIT_FAILURE); + // } + //} while(true) { diff --git a/RtspFace/make.sh b/RtspFace/make.sh index 1fa56b8..3faa727 100644 --- a/RtspFace/make.sh +++ b/RtspFace/make.sh @@ -94,5 +94,6 @@ $LDFLAGS -o rtsp_face #export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBX264_BASE/lib:$FFMPEG_BASE/lib:$SENSETIMEFACESDK_BASE/libs/linux-x86_64:$LOGGER_BASE/lib64:$DLIB_BASE/build/dlib -#./rtsp_face rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream +#./rtsp_face rtsp://admin:a1234567@192.168.1.68:554/h264/ch1/main/av_stream #rtsp://admin:a1234567@192.168.1.68:554/h264/ch1/main/av_stream +#rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/main/av_stream -- Gitblit v1.8.0