From 5cf652629fb40796cd2e0ab17c3617ed52365473 Mon Sep 17 00:00:00 2001
From: pans <pans@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期五, 18 八月 2017 10:32:05 +0800
Subject: [PATCH] capnp client fix bug
---
RtspFace/PL_AndroidMediaCodecEncoder.cpp | 35 +++++++++++++++++++++++++++++++++--
1 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/RtspFace/PL_AndroidMediaCodecEncoder.cpp b/RtspFace/PL_AndroidMediaCodecEncoder.cpp
index ca2b98b..3ce90d6 100644
--- a/RtspFace/PL_AndroidMediaCodecEncoder.cpp
+++ b/RtspFace/PL_AndroidMediaCodecEncoder.cpp
@@ -82,6 +82,7 @@
PL_AndroidMediaCodecEncoder_Config* config = (PL_AndroidMediaCodecEncoder_Config*)args;
in->config = *config;
+ // see: developer.android.com/reference/android/media/MediaFormat.html#KEY_PROFILE
AMediaFormat* format = AMediaFormat_new();
AMediaFormat_setString(format, AMEDIAFORMAT_KEY_MIME, config->ak_mime.c_str());
@@ -90,12 +91,20 @@
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_BIT_RATE, config->ak_bit_rate);
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_FRAME_RATE, config->ak_frame_rate);
- AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, config->ak_i_frame_interval);
+ AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_I_FRAME_INTERVAL, config->ak_i_frame_interval); // android multipled 10
+ AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_CHANNEL_COUNT, 1);
+ //AMediaFormat_setInt32(format, "profile", 0x00000100);
// see: https://developer.android.com/reference/android/media/MediaCodecInfo.CodecCapabilities.html#COLOR_FormatYUV420Flexible
#define AMEDIA_COLOR_FormatYUV420Flexible 0x7f420888
AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_COLOR_FORMAT, config->ak_color_format);
//AMediaFormat_setInt32(format, AMEDIAFORMAT_KEY_STRIDE, config->ak_width * 2);
+
+ if (config->codecProfileLevel.profile != 0)
+ AMediaFormat_setInt32(format, "profile", config->codecProfileLevel.profile);
+ if (config->codecProfileLevel.level != 0)
+ AMediaFormat_setInt32(format, "level", config->codecProfileLevel.level);
+
//uint8_t sps[] = {0x0,0x0,0x0,0x1, 0x67, 0x42, 0x00, 0x2A, 0x95, 0xA8, 0x1E, 0x00, 0x89, 0xF9, 0x61, 0x00, 0x00, 0x07, 0x08, 0x00, 0x01, 0x5F, 0x90, 0x04};
//uint8_t pps[] = {0x0,0x0,0x0,0x1, 0x68, 0xCE, 0x3C, 0x80};
@@ -231,7 +240,7 @@
pm.buffSize = 0;
//static size_t f = 0;
- //static FILE *pFile = fopen("/sdcard/aa.264", "wb");
+ //static FILE *pFile = fopen("/data/aa.264", "wb");
//fwrite(in->buffer, sizeof(char), in->buffSize, pFile);
//if (++f > 400){
// fclose(pFile);
@@ -251,6 +260,28 @@
{
auto format = AMediaCodec_getOutputFormat(in->codec);
LOGP(INFO, "format changed to: %s", AMediaFormat_toString(format));
+
+ uint8_t* sps = nullptr;
+ size_t spsSize = 0;
+ uint8_t* pps = nullptr;
+ size_t ppsSize = 0;
+
+ AMediaFormat_getBuffer(format, "csd-0", (void**)&sps, &spsSize); // sps
+ AMediaFormat_getBuffer(format, "csd-1", (void**)&pps, &ppsSize); // pps
+
+ if (spsSize != 0)
+ {
+ char* tmp = nullptr;
+ std::string spsStr = tmp = base64_encode(((const char*)sps) + 4, spsSize - 4);//#todo aux
+ delete[] tmp;
+ std::string ppsStr = tmp = base64_encode(((const char*)pps) + 4, ppsSize - 4);
+ delete[] tmp;
+ tmp = nullptr;
+
+ this->manager->set_param(PLGP_ENC_SPS_B64, spsStr);
+ this->manager->set_param(PLGP_ENC_PPS_B64, ppsStr);
+ }
+
AMediaFormat_delete(format);
}
else if (outputBuffIdx == AMEDIACODEC_INFO_TRY_AGAIN_LATER)
--
Gitblit v1.8.0