Move previous packet to a local variable
It is only used from run_recorder().
This commit is contained in:
parent
b6744e7887
commit
db5751a76a
2 changed files with 8 additions and 12 deletions
|
@ -138,6 +138,10 @@ run_recorder(void *data) {
|
||||||
|
|
||||||
int64_t pts_origin = AV_NOPTS_VALUE;
|
int64_t pts_origin = AV_NOPTS_VALUE;
|
||||||
|
|
||||||
|
// We can write a packet only once we received the next one so that we can
|
||||||
|
// set its duration (next_pts - current_pts)
|
||||||
|
struct sc_record_packet *previous = NULL;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
sc_mutex_lock(&recorder->mutex);
|
sc_mutex_lock(&recorder->mutex);
|
||||||
|
|
||||||
|
@ -150,7 +154,7 @@ run_recorder(void *data) {
|
||||||
|
|
||||||
if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) {
|
if (recorder->stopped && sc_queue_is_empty(&recorder->queue)) {
|
||||||
sc_mutex_unlock(&recorder->mutex);
|
sc_mutex_unlock(&recorder->mutex);
|
||||||
struct sc_record_packet *last = recorder->previous;
|
struct sc_record_packet *last = previous;
|
||||||
if (last) {
|
if (last) {
|
||||||
// assign an arbitrary duration to the last packet
|
// assign an arbitrary duration to the last packet
|
||||||
last->packet->duration = 100000;
|
last->packet->duration = 100000;
|
||||||
|
@ -183,12 +187,9 @@ run_recorder(void *data) {
|
||||||
rec->packet->dts = rec->packet->pts;
|
rec->packet->dts = rec->packet->pts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// recorder->previous is only written from this thread, no need to lock
|
|
||||||
struct sc_record_packet *previous = recorder->previous;
|
|
||||||
recorder->previous = rec;
|
|
||||||
|
|
||||||
if (!previous) {
|
if (!previous) {
|
||||||
// we just received the first packet
|
// we just received the first packet
|
||||||
|
previous = rec;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +213,8 @@ run_recorder(void *data) {
|
||||||
sc_mutex_unlock(&recorder->mutex);
|
sc_mutex_unlock(&recorder->mutex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
previous = rec;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!recorder->failed) {
|
if (!recorder->failed) {
|
||||||
|
@ -256,7 +259,6 @@ sc_recorder_open(struct sc_recorder *recorder, const AVCodec *input_codec) {
|
||||||
recorder->stopped = false;
|
recorder->stopped = false;
|
||||||
recorder->failed = false;
|
recorder->failed = false;
|
||||||
recorder->header_written = false;
|
recorder->header_written = false;
|
||||||
recorder->previous = NULL;
|
|
||||||
|
|
||||||
const char *format_name = sc_recorder_get_format_name(recorder->format);
|
const char *format_name = sc_recorder_get_format_name(recorder->format);
|
||||||
assert(format_name);
|
assert(format_name);
|
||||||
|
|
|
@ -34,12 +34,6 @@ struct sc_recorder {
|
||||||
bool stopped; // set on recorder_close()
|
bool stopped; // set on recorder_close()
|
||||||
bool failed; // set on packet write failure
|
bool failed; // set on packet write failure
|
||||||
struct sc_recorder_queue queue;
|
struct sc_recorder_queue queue;
|
||||||
|
|
||||||
// we can write a packet only once we received the next one so that we can
|
|
||||||
// set its duration (next_pts - current_pts)
|
|
||||||
// "previous" is only accessed from the recorder thread, so it does not
|
|
||||||
// need to be protected by the mutex
|
|
||||||
struct sc_record_packet *previous;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Reference in a new issue