Only set valid PTS/DTS
When the PTS is valid, set both PTS and DTS to avoid FFmpeg warnings. Since configuration packets have no PTS, do not record these packets.
This commit is contained in:
parent
27686e9361
commit
2cd99e7205
3 changed files with 33 additions and 11 deletions
|
@ -15,6 +15,7 @@
|
||||||
#include "recorder.h"
|
#include "recorder.h"
|
||||||
|
|
||||||
#define BUFSIZE 0x10000
|
#define BUFSIZE 0x10000
|
||||||
|
#define MEDIA_CODEC_FLAG_CONFIG 2 // MediaCodec.BUFFER_FLAG_CODEC_CONFIG
|
||||||
|
|
||||||
static inline uint64_t from_be(uint8_t *b, int size)
|
static inline uint64_t from_be(uint8_t *b, int size)
|
||||||
{
|
{
|
||||||
|
@ -45,6 +46,7 @@ static int read_packet(void *opaque, uint8_t *buf, int buf_size) {
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
decoder->pts = from_be(header, 8);
|
decoder->pts = from_be(header, 8);
|
||||||
|
decoder->buffer_info_flags = from_be(header + 8, 4);
|
||||||
remaining = from_be(header + 12, 4);
|
remaining = from_be(header + 12, 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,7 +143,13 @@ static int run_decoder(void *data) {
|
||||||
|
|
||||||
while (!av_read_frame(format_ctx, &packet)) {
|
while (!av_read_frame(format_ctx, &packet)) {
|
||||||
if (decoder->recorder) {
|
if (decoder->recorder) {
|
||||||
|
// do not record configuration packets
|
||||||
|
// (they contain no media data and have no PTS/DTS)
|
||||||
|
// FIXME do not use MediaCodec specific flags
|
||||||
|
if (!(decoder->buffer_info_flags & MEDIA_CODEC_FLAG_CONFIG)) {
|
||||||
packet.pts = decoder->pts;
|
packet.pts = decoder->pts;
|
||||||
|
packet.dts = decoder->pts;
|
||||||
|
|
||||||
// no need to rescale with av_packet_rescale_ts(), the timestamps
|
// no need to rescale with av_packet_rescale_ts(), the timestamps
|
||||||
// are in microseconds both in input and output
|
// are in microseconds both in input and output
|
||||||
if (!recorder_write(decoder->recorder, &packet)) {
|
if (!recorder_write(decoder->recorder, &packet)) {
|
||||||
|
@ -150,6 +158,7 @@ static int run_decoder(void *data) {
|
||||||
goto run_quit;
|
goto run_quit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// the new decoding/encoding API has been introduced by:
|
// the new decoding/encoding API has been introduced by:
|
||||||
// <http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=7fc329e2dd6226dfecaa4a1d7adf353bf2773726>
|
// <http://git.videolan.org/?p=ffmpeg.git;a=commitdiff;h=7fc329e2dd6226dfecaa4a1d7adf353bf2773726>
|
||||||
|
|
|
@ -10,12 +10,13 @@
|
||||||
struct frames;
|
struct frames;
|
||||||
|
|
||||||
struct decoder {
|
struct decoder {
|
||||||
uint64_t pts;
|
|
||||||
struct frames *frames;
|
struct frames *frames;
|
||||||
socket_t video_socket;
|
socket_t video_socket;
|
||||||
SDL_Thread *thread;
|
SDL_Thread *thread;
|
||||||
SDL_mutex *mutex;
|
SDL_mutex *mutex;
|
||||||
struct recorder *recorder;
|
struct recorder *recorder;
|
||||||
|
uint64_t pts;
|
||||||
|
uint32_t buffer_info_flags;
|
||||||
int remaining;
|
int remaining;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
private int bitRate;
|
private int bitRate;
|
||||||
private int frameRate;
|
private int frameRate;
|
||||||
private int iFrameInterval;
|
private int iFrameInterval;
|
||||||
|
private long ptsOrigin;
|
||||||
|
|
||||||
public ScreenEncoder(int bitRate, int frameRate, int iFrameInterval) {
|
public ScreenEncoder(int bitRate, int frameRate, int iFrameInterval) {
|
||||||
this.bitRate = bitRate;
|
this.bitRate = bitRate;
|
||||||
|
@ -93,11 +94,22 @@ public class ScreenEncoder implements Device.RotationListener {
|
||||||
}
|
}
|
||||||
if (outputBufferId >= 0) {
|
if (outputBufferId >= 0) {
|
||||||
ByteBuffer codecBuffer = codec.getOutputBuffer(outputBufferId);
|
ByteBuffer codecBuffer = codec.getOutputBuffer(outputBufferId);
|
||||||
bBuffer.position(0);
|
bBuffer.clear();
|
||||||
bBuffer.putLong(bufferInfo.presentationTimeUs);
|
|
||||||
|
long pts;
|
||||||
|
if ((bufferInfo.flags & MediaCodec.BUFFER_FLAG_CODEC_CONFIG) != 0) {
|
||||||
|
pts = 0; // non-media data packet
|
||||||
|
} else {
|
||||||
|
if (ptsOrigin == 0) {
|
||||||
|
ptsOrigin = bufferInfo.presentationTimeUs;
|
||||||
|
}
|
||||||
|
pts = bufferInfo.presentationTimeUs - ptsOrigin;
|
||||||
|
}
|
||||||
|
|
||||||
|
bBuffer.putLong(pts);
|
||||||
bBuffer.putInt(bufferInfo.flags);
|
bBuffer.putInt(bufferInfo.flags);
|
||||||
bBuffer.putInt(codecBuffer.remaining());
|
bBuffer.putInt(codecBuffer.remaining());
|
||||||
bBuffer.position(0);
|
bBuffer.flip();
|
||||||
IO.writeFully(fd, bBuffer);
|
IO.writeFully(fd, bBuffer);
|
||||||
IO.writeFully(fd, codecBuffer);
|
IO.writeFully(fd, codecBuffer);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue