From e11e7bc7f455bf19abea5ab0e17c894a913515cc Mon Sep 17 00:00:00 2001
From: xingzilong <xingzilong@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期四, 17 八月 2017 17:41:32 +0800
Subject: [PATCH] 客户端修改SPS PPS
---
RtspFace/PL_RTSPClient.cpp | 17 +++++++++++++++++
RtspFace/PL_AndroidMediaCodecDecoder_ndk.cpp | 41 +++++++++++++++++++++++++++++------------
2 files changed, 46 insertions(+), 12 deletions(-)
diff --git a/RtspFace/PL_AndroidMediaCodecDecoder_ndk.cpp b/RtspFace/PL_AndroidMediaCodecDecoder_ndk.cpp
index 79a8a46..d56500d 100644
--- a/RtspFace/PL_AndroidMediaCodecDecoder_ndk.cpp
+++ b/RtspFace/PL_AndroidMediaCodecDecoder_ndk.cpp
@@ -11,6 +11,7 @@
#include <stdlib.h>
#include <liveMedia/liveMedia.hh>
+
// see: https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities.html#COLOR_FormatYUV420Flexible
#define AMEDIA_COLOR_FormatYUV420Flexible 0x7f420888
#define AMEDIA_COLOR_FormatYUV420Planar 0x00000013 // 19, I420
@@ -56,6 +57,7 @@
void reset()
{
+ auxIsSet = false;
buffSize = 0;
inputFrameCount = 0;
@@ -140,10 +142,11 @@
*/
// J0LgKI1oCgPaEAAAAwAQAAADAoDxB6gA,KM4ySA==
- //uint8_t sps[] = {0x27,0x42,0xe0,0x28,0x8d,0x68,0x0a,0x03,0xda,0x10,0x00,0x00,0x03,0x00,0x10,0x00,0x00,0x03,0x02,0x80,0xf1,0x07,0xa8,0x00};
- //uint8_t pps[] = {0x28,0xce,0x32,0x48};
- //AMediaFormat_setBuffer(format, "csd-0", sps, sizeof(sps)); // sps
- //AMediaFormat_setBuffer(format, "csd-1", pps, sizeof(pps)); // pps
+
+// uint8_t sps[] = {0x27,0x42,0xe0,0x28,0x8d,0x68,0x0a,0x03,0xda,0x10,0x00,0x00,0x03,0x00,0x10,0x00,0x00,0x03,0x02,0x80,0xf1,0x07,0xa8,0x00};
+// uint8_t pps[] = {0x28,0xce,0x32,0x48};
+// AMediaFormat_setBuffer(format, "csd-0", sps, sizeof(sps)); // sps
+// AMediaFormat_setBuffer(format, "csd-1", pps, sizeof(pps)); // pps
// 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}
@@ -200,15 +203,29 @@
if (!in->auxIsSet)
{
//#todo
+ std::string base64_sps = this->manager->get_param(PLGP_DEC_SPS_B64);
+ std::string base64_pps = this->manager->get_param(PLGP_DEC_PPS_B64);
// find PLGP_DEC_SPS_B64 PLGP_DEC_PPS_B64 in this->manager else nothing
// base64 decode
+ if((!base64_sps.empty())
+ &&(!base64_pps.empty()))
+ {
+ size_t result_sps = 0;
+ size_t result_ps = 0;
- //AMediaFormat* format = AMediaCodec_getOutputFormat(in->codec);
- //AMediaFormat_setBuffer(format, "csd-1", pps, sizeof(pps)); // pps
- //AMediaCodec_setParameters
- // #todo delete format
+ uint8_t* uc_sps = base64_decode(base64_sps.c_str(),base64_sps.length(),result_sps);
+ uint8_t* uc_pps = base64_decode(base64_pps.c_str(),base64_pps.length(),result_ps);
- in->auxIsSet = true;
+ AMediaFormat* format = AMediaCodec_getOutputFormat(in->codec);
+ AMediaFormat_setBuffer(format, "csd-0", uc_sps, result_sps); // sps
+ AMediaFormat_setBuffer(format, "csd-1", uc_pps, result_sps); // pps
+ AMediaCodec_setParameters(in->codec,format);
+ // #todo delete format
+ AMediaFormat_delete(format);
+
+ in->auxIsSet = true;
+ }
+
}
MB_Frame* frame = (MB_Frame*)pm.buffer;
@@ -218,9 +235,9 @@
return false;
}
- //static FILE *pFile = fopen("/data/bb.264", "wb");
- //fwrite(frame->buffer, sizeof(char), frame->buffSize, pFile);
- //fflush(pFile);
+// static FILE *pFile = fopen("/data/bb.264", "wb");
+// fwrite(frame->buffer, sizeof(char), frame->buffSize, pFile);
+// fflush(pFile);
ssize_t bufidx = AMediaCodec_dequeueInputBuffer(in->codec, 2000);
LOGP(DEBUG, "input buffer bufidx=%zd, inputFrameCount=%d", bufidx, in->inputFrameCount++);
diff --git a/RtspFace/PL_RTSPClient.cpp b/RtspFace/PL_RTSPClient.cpp
index c2bd969..df36683 100644
--- a/RtspFace/PL_RTSPClient.cpp
+++ b/RtspFace/PL_RTSPClient.cpp
@@ -219,6 +219,17 @@
pm.buffSize = 0;
pm.former = this;
+// if(nullptr!=pm.buffer)
+// {
+// MB_Frame* frame = (MB_Frame*)pm.buffer;
+// if (frame->type == MB_Frame::MBFT_H264_NALU)
+// {
+// static FILE *pFile = fopen("/data/bb1.264", "wb");
+// fwrite(frame->buffer, sizeof(char), frame->buffSize, pFile);
+// fflush(pFile);
+// }
+// }
+
return true;
}
@@ -249,11 +260,17 @@
sprintf(tmp, "%u", param.height); client->manager->set_param(PLGP_RTSP_HEIGHT, std::string(tmp));
sprintf(tmp, "%u", param.fps); client->manager->set_param(PLGP_RTSP_FPS, std::string(tmp));
+ size_t _flag = 0;
if (param.fmtp.find_first_of(',') != std::string::npos)
{
//#todo
// split fmpt to base64 of sps,pps
// set to PLGP_DEC_SPS_B64 PLGP_DEC_PPS_B64
+ _flag = param.fmtp.find_first_of(',');
+ std::string _base64_sps = param.fmtp.substr(0,_flag);
+ std::string _base64_pps = param.fmtp.substr(_flag,param.fmtp.length());
+ client->manager->set_param(PLGP_DEC_SPS_B64,_base64_sps);
+ client->manager->set_param(PLGP_DEC_PPS_B64,_base64_pps);
}
/*
--
Gitblit v1.8.0