MT#65420 unify player start code

Change-Id: I74e03077541e48cadff65c09a903f4ee6e48a481
pull/2169/head
Richard Fuchs 4 weeks ago
parent df7996b7a0
commit 5ee259b234

@ -2873,7 +2873,7 @@ static void __call_monologue_init_from_flags(struct call_monologue *ml, struct c
);
media_player_new(&ml->rec_player, ml, NULL, &opts);
if (!media_player_add(ml->rec_player, opts))
if (!media_player_play(ml->rec_player, opts))
ilog(LOG_WARN, "Failed to add media player for recording announcement");
}
#endif

@ -34,15 +34,6 @@ typedef enum {
MPC_CACHED = 1,
} mp_cached_code;
#ifdef WITH_TRANSCODING
static bool media_player_play_file(struct media_player *mp, media_player_opts_t opts);
static bool media_player_play_blob(struct media_player *mp, media_player_opts_t opts);
static bool media_player_play_db(struct media_player *mp, media_player_opts_t opts);
static bool media_player_add_file(struct media_player *mp, media_player_opts_t opts);
static bool media_player_add_blob(struct media_player *mp, media_player_opts_t opts);
static bool media_player_add_db(struct media_player *mp, media_player_opts_t opts);
#endif
#ifdef WITH_TRANSCODING
static struct timerthread media_player_thread;
static __thread MYSQL *mysql_conn;
@ -132,6 +123,9 @@ static bool media_player_read_packet(struct media_player *mp);
static mp_cached_code __media_player_add_blob_id(struct media_player *mp,
media_player_opts_t opts,
const rtp_payload_type *dst_pt);
static mp_cached_code __media_player_add_db(struct media_player *mp,
media_player_opts_t opts,
const rtp_payload_type *dst_pt);
static int media_player_read_first_frame(struct media_player *mp);
static int media_player_seek_first_frame(struct media_player *mp);
@ -1534,45 +1528,37 @@ static mp_cached_code __media_player_add_file(struct media_player *mp,
return MPC_OK;
}
#endif
// call->master_lock held in W
static bool media_player_play_file(struct media_player *mp, media_player_opts_t opts) {
bool media_player_play(struct media_player *mp, media_player_opts_t opts) {
#ifdef WITH_TRANSCODING
const rtp_payload_type *dst_pt = media_player_play_init(mp);
if (!dst_pt)
return false;
mp_cached_code ret = __media_player_add_file(mp, opts, dst_pt);
mp_cached_code ret = MPC_ERR;
if (opts.file.len)
ret = __media_player_add_file(mp, opts, dst_pt);
else if (opts.blob.len) {
// make sure to reset db_id before using blob
opts.db_id = 0;
ret = __media_player_add_blob_id(mp, opts, dst_pt);
}
else if (opts.db_id > 0)
ret = __media_player_add_db(mp, opts, dst_pt);
if (ret == MPC_CACHED)
return true;
if (ret == MPC_ERR)
return false;
return media_player_play_start(mp, dst_pt, opts.codec_set);
}
#endif
bool media_player_add(struct media_player *mp, media_player_opts_t opts) {
#ifdef WITH_TRANSCODING
if (opts.file.len)
return media_player_add_file(mp, opts);
else if (opts.blob.len)
return media_player_add_blob(mp, opts);
else if (opts.db_id > 0)
return media_player_add_db(mp, opts);
else
return false;
#else
return false;
#endif
}
#ifdef WITH_TRANSCODING
// call->master_lock held in W
static bool media_player_add_file(struct media_player *mp, media_player_opts_t opts) {
int ret = __media_player_add_file(mp, opts, NULL);
return ret == 0;
}
#endif
/**
* When to_ml is given, check MoH capabilities of it,
@ -1716,7 +1702,7 @@ const char * call_check_moh(struct call_monologue *from_ml, struct call_monologu
#endif
}
const char * call_play_media_for_ml(struct call_monologue *ml,
const char *call_play_media_for_ml(struct call_monologue *ml,
media_player_opts_t opts, sdp_ng_flags *flags)
{
#ifdef WITH_TRANSCODING
@ -1737,20 +1723,9 @@ const char * call_play_media_for_ml(struct call_monologue *ml,
media_player_new(&ml->player, ml, NULL, &opts);
}
if (opts.file.len) {
if (!media_player_play_file(ml->player, opts))
return "Failed to start media playback from file";
}
else if (opts.blob.len) {
if (!media_player_play_blob(ml->player, opts))
return "Failed to start media playback from blob";
}
else if (opts.db_id > 0) {
if (!media_player_play_db(ml->player, opts))
return "Failed to start media playback from database";
}
else
return "No media file specified";
if (!media_player_play(ml->player, opts))
return "Failed to start media playback";
return NULL;
#else
return "Not implemented";
@ -1886,32 +1861,6 @@ err:
}
// call->master_lock held in W
static bool media_player_play_blob(struct media_player *mp, media_player_opts_t opts) {
const rtp_payload_type *dst_pt = media_player_play_init(mp);
if (!dst_pt)
return false;
/* make sure to reset db_id before using blob */
opts.db_id = 0;
mp_cached_code ret = __media_player_add_blob_id(mp, opts, dst_pt);
if (ret == MPC_CACHED)
return true;
if (ret == MPC_ERR)
return false;
return media_player_play_start(mp, dst_pt, opts.codec_set);
}
// call->master_lock held in W
static bool media_player_add_blob(struct media_player *mp, media_player_opts_t opts) {
/* make sure to reset db_id before using blob */
opts.db_id = 0;
int ret = __media_player_add_blob_id(mp, opts, NULL);
return ret != MPC_ERR;
}
static int __connect_db(void) {
if (mysql_conn) {
mysql_close(mysql_conn);
@ -2066,28 +2015,6 @@ static mp_cached_code __media_player_add_db(struct media_player *mp,
return __media_player_add_blob_id(mp, opts, dst_pt);
}
// call->master_lock held in W
static bool media_player_play_db(struct media_player *mp, media_player_opts_t opts) {
const rtp_payload_type *dst_pt = media_player_play_init(mp);
if (!dst_pt)
return false;
mp_cached_code ret = __media_player_add_db(mp, opts, dst_pt);
if (ret == MPC_CACHED)
return true;
if (ret == MPC_ERR)
return false;
return media_player_play_start(mp, dst_pt, opts.codec_set);
}
// call->master_lock held in W
static bool media_player_add_db(struct media_player *mp, media_player_opts_t opts) {
int ret = __media_player_add_db(mp, opts, NULL);
return ret != MPC_ERR;
}
static void media_player_run(void *ptr) {
struct media_player *mp = ptr;
call_t *call = mp->call;

@ -123,7 +123,7 @@ struct send_timer {
#define MPO(...) (media_player_opts_t){__VA_ARGS__}
void media_player_new(struct media_player **, struct call_monologue *, struct ssrc_entry_call *prev_ssrc, media_player_opts_t *);
bool media_player_add(struct media_player *mp, media_player_opts_t opts);
bool media_player_play(struct media_player *mp, media_player_opts_t opts);
bool media_player_start(struct media_player *);
long long media_player_stop(struct media_player *);
bool media_player_is_active(struct call_monologue *);
@ -137,7 +137,7 @@ bool media_player_pt_match(const struct media_player *mp, const rtp_payload_type
void media_player_add_packet(struct media_player *mp, char *buf, size_t len,
int64_t us_dur, unsigned long long pts);
const char * call_play_media_for_ml(struct call_monologue *ml,
const char *call_play_media_for_ml(struct call_monologue *ml,
media_player_opts_t opts, sdp_ng_flags *flags);
long long call_stop_media_for_ml(struct call_monologue *ml);
bool call_ml_wants_moh(struct call_monologue *from_ml, struct call_monologue *to_ml, enum ng_opmode opmode);

Loading…
Cancel
Save