feat: sync scrcpy

This commit is contained in:
rankun 2020-01-15 10:38:27 +08:00
commit c957bfc798
4 changed files with 12 additions and 7 deletions

View file

@ -197,7 +197,6 @@ void Device::startServer()
//m_server->start("192.168.0.174:5555", 27183, m_maxSize, m_bitRate, ""); //m_server->start("192.168.0.174:5555", 27183, m_maxSize, m_bitRate, "");
// only one devices, serial can be null // only one devices, serial can be null
// mark: crop input format: "width:height:x:y" or - for no crop, for example: "100:200:0:0" // mark: crop input format: "width:height:x:y" or - for no crop, for example: "100:200:0:0"
// sendFrameMeta for recorder mp4
Server::ServerParams params; Server::ServerParams params;
params.serial = m_params.serial; params.serial = m_params.serial;
params.localPort = m_params.localPort; params.localPort = m_params.localPort;
@ -205,7 +204,6 @@ void Device::startServer()
params.bitRate = m_params.bitRate; params.bitRate = m_params.bitRate;
params.maxFps = m_params.maxFps; params.maxFps = m_params.maxFps;
params.crop = "-"; params.crop = "-";
params.sendFrameMeta = m_recorder ? true : false;
params.control = true; params.control = true;
params.useReverse = m_params.useReverse; params.useReverse = m_params.useReverse;
m_server->start(params); m_server->start(params);

View file

@ -105,12 +105,23 @@ void Recorder::close()
bool Recorder::write(AVPacket *packet) bool Recorder::write(AVPacket *packet)
{ {
if (!m_headerWritten) { if (!m_headerWritten) {
if (packet->pts != AV_NOPTS_VALUE) {
qCritical("The first packet is not a config packet");
return false;
}
bool ok = recorderWriteHeader(packet); bool ok = recorderWriteHeader(packet);
if (!ok) { if (!ok) {
return false; return false;
} }
m_headerWritten = true; m_headerWritten = true;
return true;
} }
if (packet->pts == AV_NOPTS_VALUE) {
// ignore config packets
return true;
}
recorderRescalePacket(packet); recorderRescalePacket(packet);
return av_write_frame(m_formatCtx, packet) >= 0; return av_write_frame(m_formatCtx, packet) >= 0;
} }
@ -154,9 +165,6 @@ bool Recorder::recorderWriteHeader(const AVPacket* packet)
int ret = avformat_write_header(m_formatCtx, NULL); int ret = avformat_write_header(m_formatCtx, NULL);
if (ret < 0) { if (ret < 0) {
qCritical("Failed to write header recorder file"); qCritical("Failed to write header recorder file");
free(extradata);
avio_close(m_formatCtx->pb);
avformat_free_context(m_formatCtx);
return false; return false;
} }
return true; return true;

View file

@ -142,7 +142,7 @@ bool Server::execute()
} else { } else {
args << m_params.crop; args << m_params.crop;
} }
args << (m_params.sendFrameMeta ? "true" : "false"); args << "true"; // always send frame meta (packet boundaries + timestamp)
args << (m_params.control ? "true" : "false"); args << (m_params.control ? "true" : "false");
// adb -s P7C0218510000537 shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 0 8000000 false // adb -s P7C0218510000537 shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 0 8000000 false

View file

@ -29,7 +29,6 @@ public:
quint32 bitRate = 8000000; // 视频比特率 quint32 bitRate = 8000000; // 视频比特率
quint32 maxFps = 60; // 视频最大帧率 quint32 maxFps = 60; // 视频最大帧率
QString crop = "-"; // 视频裁剪 QString crop = "-"; // 视频裁剪
bool sendFrameMeta = false; // 是否发送mp4帧数据
bool control = true; // 安卓端是否接收键鼠控制 bool control = true; // 安卓端是否接收键鼠控制
bool useReverse = true; // true:先使用adb reverse失败后自动使用adb forwardfalse:直接使用adb forward bool useReverse = true; // true:先使用adb reverse失败后自动使用adb forwardfalse:直接使用adb forward
}; };