report buffer full/empty from hls bus messages

This commit is contained in:
F. Duncanh
2025-04-26 16:17:23 -04:00
parent 3a488897b4
commit 5f2fbfe88b
4 changed files with 56 additions and 25 deletions

View File

@@ -279,10 +279,10 @@ http_handler_playback_info(raop_conn_t *conn, http_request_t *request, http_resp
playback_info_t playback_info; playback_info_t playback_info;
playback_info.stallcount = 0; playback_info.stallcount = 0;
playback_info.ready_to_play = true; // ???; //playback_info.playback_buffer_empty = false; // maybe need to get this from playbin
playback_info.playback_buffer_empty = false; // maybe need to get this from playbin //playback_info.playback_buffer_full = true;
playback_info.playback_buffer_full = true; //ayback_info.ready_to_play = true; // ???;
playback_info.playback_likely_to_keep_up = true; //ayback_info.playback_likely_to_keep_up = true;
conn->raop->callbacks.on_video_acquire_playback_info(conn->raop->callbacks.cls, &playback_info); conn->raop->callbacks.on_video_acquire_playback_info(conn->raop->callbacks.cls, &playback_info);
if (playback_info.duration == -1.0) { if (playback_info.duration == -1.0) {
@@ -749,29 +749,44 @@ http_handler_hls(raop_conn_t *conn, http_request_t *request, http_response_t *r
const char *url = http_request_get_url(request); const char *url = http_request_get_url(request);
const char* upgrade = http_request_get_header(request, "Upgrade"); const char* upgrade = http_request_get_header(request, "Upgrade");
if (upgrade) { if (upgrade) {
//don't accept Upgrade: h2c request ? //don't accept Upgrade: h2c request ?
return; char *header_str = NULL;
http_request_get_header_string(request, &header_str);
logger_log(conn->raop->logger, LOGGER_INFO,
"%s\nhls upgrade request declined", header_str);
free (header_str);
return;
} }
if (!strcmp(url, "/master.m3u8")){ if (!strcmp(url, "/master.m3u8")){
char * master_playlist = get_master_playlist(conn->raop->airplay_video); char * master_playlist = get_master_playlist(conn->raop->airplay_video);
size_t len = strlen(master_playlist); if (master_playlist) {
char * data = (char *) malloc(len + 1); size_t len = strlen(master_playlist);
memcpy(data, master_playlist, len); char * data = (char *) malloc(len + 1);
data[len] = '\0'; memcpy(data, master_playlist, len);
*response_data = data; data[len] = '\0';
*response_datalen = (int ) len; *response_data = data;
*response_datalen = (int ) len;
} else {
logger_log(conn->raop->logger, LOGGER_ERR,"requested master playlist %s not found", url);
*response_datalen = 0;
}
} else { } else {
char *media_playlist = get_media_playlist(conn->raop->airplay_video, url); char *media_playlist = get_media_playlist(conn->raop->airplay_video, url);
assert(media_playlist); if (media_playlist) {
char *data = adjust_yt_condensed_playlist(media_playlist); char *data = adjust_yt_condensed_playlist(media_playlist);
*response_data = data; *response_data = data;
*response_datalen = strlen(data); *response_datalen = strlen(data);
float duration = 0.0f; float duration = 0.0f;
int chunks = analyze_media_playlist(data, &duration); int chunks = analyze_media_playlist(data, &duration);
logger_log(conn->raop->logger, LOGGER_INFO, logger_log(conn->raop->logger, LOGGER_INFO,
"Requested media_playlist %s has %5d chunks, total duration %9.3f secs", url, chunks, duration); "Requested media_playlist %s has %5d chunks, total duration %9.3f secs", url, chunks, duration);
} } else {
logger_log(conn->raop->logger, LOGGER_ERR,"requested media playlist %s not found", url);
*response_datalen = 0;
}
}
http_response_add_header(response, "Access-Control-Allow-Headers", "Content-type"); http_response_add_header(response, "Access-Control-Allow-Headers", "Content-type");
http_response_add_header(response, "Access-Control-Allow-Origin", "*"); http_response_add_header(response, "Access-Control-Allow-Origin", "*");

View File

@@ -52,6 +52,8 @@ static gint64 hls_seek_end = 0;
static gint64 hls_duration; static gint64 hls_duration;
static gboolean hls_seek_enabled; static gboolean hls_seek_enabled;
static gboolean hls_playing; static gboolean hls_playing;
static gboolean hls_buffer_empty;
static gboolean hls_buffer_full;
typedef enum { typedef enum {
@@ -232,6 +234,9 @@ void video_renderer_init(logger_t *render_logger, const char *server_name, vide
hls_seek_start = -1; hls_seek_start = -1;
hls_seek_end = -1; hls_seek_end = -1;
hls_duration = -1; hls_duration = -1;
hls_buffer_empty = TRUE;
hls_buffer_empty = FALSE;
/* this call to g_set_application_name makes server_name appear in the X11 display window title bar, */ /* this call to g_set_application_name makes server_name appear in the X11 display window title bar, */
/* (instead of the program name uxplay taken from (argv[0]). It is only set one time. */ /* (instead of the program name uxplay taken from (argv[0]). It is only set one time. */
@@ -660,12 +665,16 @@ gboolean gstreamer_pipeline_bus_callback(GstBus *bus, GstMessage *message, void
if (hls_video) { if (hls_video) {
gint percent = -1; gint percent = -1;
gst_message_parse_buffering(message, &percent); gst_message_parse_buffering(message, &percent);
hls_buffer_empty = TRUE;
hls_buffer_full = FALSE;
if (percent > 0) { if (percent > 0) {
hls_buffer_empty = FALSE;
renderer_type[type]->buffering_level = percent; renderer_type[type]->buffering_level = percent;
logger_log(logger, LOGGER_DEBUG, "Buffering :%d percent done", percent); logger_log(logger, LOGGER_DEBUG, "Buffering :%d percent done", percent);
if (percent < 100) { if (percent < 100) {
gst_element_set_state (renderer_type[type]->pipeline, GST_STATE_PAUSED); gst_element_set_state (renderer_type[type]->pipeline, GST_STATE_PAUSED);
} else { } else {
hls_buffer_full = TRUE;
gst_element_set_state (renderer_type[type]->pipeline, GST_STATE_PLAYING); gst_element_set_state (renderer_type[type]->pipeline, GST_STATE_PLAYING);
} }
} }
@@ -852,16 +861,18 @@ unsigned int video_reset_callback(void * loop) {
return (unsigned int) TRUE; return (unsigned int) TRUE;
} }
bool video_get_playback_info(double *duration, double *position, float *rate) { bool video_get_playback_info(double *duration, double *position, float *rate, bool *buffer_empty, bool *buffer_full) {
gint64 pos = 0; gint64 pos = 0;
GstState state; GstState state;
*duration = 0.0; *duration = 0.0;
*position = -1.0; *position = -1.0;
*rate = 0.0f; *rate = 0.0f;
if (!renderer) { if (!renderer) {
return true; return true;
} }
*buffer_empty = (bool) hls_buffer_empty;
*buffer_full = (bool) hls_buffer_full;
gst_element_get_state(renderer->pipeline, &state, NULL, 0); gst_element_get_state(renderer->pipeline, &state, NULL, 0);
*rate = 0.0f; *rate = 0.0f;
switch (state) { switch (state) {

View File

@@ -63,7 +63,7 @@ unsigned int video_renderer_listen(void *loop, int id);
void video_renderer_destroy (); void video_renderer_destroy ();
void video_renderer_size(float *width_source, float *height_source, float *width, float *height); void video_renderer_size(float *width_source, float *height_source, float *width, float *height);
bool waiting_for_x11_window(); bool waiting_for_x11_window();
bool video_get_playback_info(double *duration, double *position, float *rate); bool video_get_playback_info(double *duration, double *position, float *rate, bool *buffer_empty, bool *buffer_full);
int video_renderer_choose_codec(bool is_h265); int video_renderer_choose_codec(bool is_h265);
unsigned int video_renderer_listen(void *loop, int id); unsigned int video_renderer_listen(void *loop, int id);
unsigned int video_reset_callback(void *loop); unsigned int video_reset_callback(void *loop);

View File

@@ -2071,7 +2071,12 @@ extern "C" void on_video_acquire_playback_info (void *cls, playback_info_t *play
int buffering_level; int buffering_level;
LOGD("on_video_acquire_playback info\n"); LOGD("on_video_acquire_playback info\n");
bool still_playing = video_get_playback_info(&playback_info->duration, &playback_info->position, bool still_playing = video_get_playback_info(&playback_info->duration, &playback_info->position,
&playback_info->rate); &playback_info->rate,
&playback_info->playback_buffer_empty,
&playback_info->playback_buffer_full);
playback_info->ready_to_play = true; //?
playback_info->playback_likely_to_keep_up = true; //?
LOGD("on_video_acquire_playback info done\n"); LOGD("on_video_acquire_playback info done\n");
if (!still_playing) { if (!still_playing) {
LOGI(" video has finished, %f", playback_info->position); LOGI(" video has finished, %f", playback_info->position);