mirror of
https://github.com/mpv-player/mpv.git
synced 2025-12-28 05:33:14 +00:00
encode: some more cleanups
This commit is contained in:
@@ -57,7 +57,6 @@ struct encode_opts {
|
||||
// interface for mplayer.c
|
||||
struct encode_lavc_context *encode_lavc_init(struct encode_opts *options,
|
||||
struct mpv_global *global);
|
||||
void encode_lavc_finish(struct encode_lavc_context *ctx);
|
||||
void encode_lavc_free(struct encode_lavc_context *ctx);
|
||||
void encode_lavc_discontinuity(struct encode_lavc_context *ctx);
|
||||
bool encode_lavc_showhelp(struct mp_log *log, struct encode_opts *options);
|
||||
|
||||
@@ -133,7 +133,7 @@ static bool value_has_flag(const char *value, const char *flag)
|
||||
}
|
||||
|
||||
#define CHECK_FAIL(ctx, val) \
|
||||
if (ctx && (ctx->failed || ctx->finished)) { \
|
||||
if (ctx && (ctx->failed)) { \
|
||||
MP_ERR(ctx, \
|
||||
"Called a function on a %s encoding context. Bailing out.\n", \
|
||||
ctx->failed ? "failed" : "finished"); \
|
||||
@@ -141,7 +141,7 @@ static bool value_has_flag(const char *value, const char *flag)
|
||||
}
|
||||
|
||||
#define CHECK_FAIL_UNLOCK(ctx, val) \
|
||||
if (ctx && (ctx->failed || ctx->finished)) { \
|
||||
if (ctx && (ctx->failed)) { \
|
||||
MP_ERR(ctx, \
|
||||
"Called a function on a %s encoding context. Bailing out.\n", \
|
||||
ctx->failed ? "failed" : "finished"); \
|
||||
@@ -155,12 +155,6 @@ int encode_lavc_available(struct encode_lavc_context *ctx)
|
||||
return ctx && ctx->avc;
|
||||
}
|
||||
|
||||
int encode_lavc_oformat_flags(struct encode_lavc_context *ctx)
|
||||
{
|
||||
CHECK_FAIL(ctx, 0);
|
||||
return ctx->avc ? ctx->avc->oformat->flags : 0;
|
||||
}
|
||||
|
||||
struct encode_lavc_context *encode_lavc_init(struct encode_opts *options,
|
||||
struct mpv_global *global)
|
||||
{
|
||||
@@ -200,8 +194,9 @@ struct encode_lavc_context *encode_lavc_init(struct encode_opts *options,
|
||||
if (*in)
|
||||
++in;
|
||||
}
|
||||
} else
|
||||
} else {
|
||||
ctx->avc->oformat = av_guess_format(NULL, filename, NULL);
|
||||
}
|
||||
|
||||
if (!ctx->avc->oformat) {
|
||||
encode_lavc_fail(ctx, "format not found\n");
|
||||
@@ -380,29 +375,12 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
|
||||
}
|
||||
|
||||
void encode_lavc_free(struct encode_lavc_context *ctx)
|
||||
{
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
if (!ctx->finished) {
|
||||
encode_lavc_fail(ctx,
|
||||
"called encode_lavc_free without encode_lavc_finish\n");
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&ctx->lock);
|
||||
talloc_free(ctx);
|
||||
}
|
||||
|
||||
void encode_lavc_finish(struct encode_lavc_context *ctx)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
if (ctx->finished)
|
||||
return;
|
||||
|
||||
if (ctx->avc) {
|
||||
if (ctx->header_written > 0)
|
||||
av_write_trailer(ctx->avc); // this is allowed to fail
|
||||
@@ -459,7 +437,8 @@ void encode_lavc_finish(struct encode_lavc_context *ctx)
|
||||
ctx->avc = NULL;
|
||||
}
|
||||
|
||||
ctx->finished = true;
|
||||
pthread_mutex_destroy(&ctx->lock);
|
||||
talloc_free(ctx);
|
||||
}
|
||||
|
||||
void encode_lavc_set_video_fps(struct encode_lavc_context *ctx, float fps)
|
||||
@@ -1193,7 +1172,6 @@ void encode_lavc_fail(struct encode_lavc_context *ctx, const char *format, ...)
|
||||
if (ctx->failed)
|
||||
return;
|
||||
ctx->failed = true;
|
||||
encode_lavc_finish(ctx);
|
||||
}
|
||||
|
||||
// vim: ts=4 sw=4 et
|
||||
|
||||
@@ -91,7 +91,6 @@ struct encode_lavc_context {
|
||||
|
||||
// has encoding failed?
|
||||
bool failed;
|
||||
bool finished;
|
||||
};
|
||||
|
||||
// interface for vo/ao drivers
|
||||
@@ -108,7 +107,6 @@ int encode_lavc_open_codec(struct encode_lavc_context *ctx,
|
||||
int encode_lavc_available(struct encode_lavc_context *ctx);
|
||||
int encode_lavc_timesyncfailed(struct encode_lavc_context *ctx);
|
||||
int encode_lavc_start(struct encode_lavc_context *ctx); // returns 1 on success
|
||||
int encode_lavc_oformat_flags(struct encode_lavc_context *ctx);
|
||||
double encode_lavc_getoffset(struct encode_lavc_context *ctx,
|
||||
AVCodecContext *codec);
|
||||
void encode_lavc_fail(struct encode_lavc_context *ctx, const char *format, ...); // report failure of encoding
|
||||
|
||||
@@ -165,7 +165,6 @@ void mp_destroy(struct MPContext *mpctx)
|
||||
uninit_video_out(mpctx);
|
||||
|
||||
#if HAVE_ENCODING
|
||||
encode_lavc_finish(mpctx->encode_lavc_ctx);
|
||||
encode_lavc_free(mpctx->encode_lavc_ctx);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user