[vlc-commits] vout: privatize vout_snapshot_t
Rémi Denis-Courmont
git at videolan.org
Sun Dec 9 20:46:01 CET 2018
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Dec 9 16:35:38 2018 +0200| [a202b0391ea2ad43ebb6d2b196adc731007b7a0a] | committer: Rémi Denis-Courmont
vout: privatize vout_snapshot_t
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=a202b0391ea2ad43ebb6d2b196adc731007b7a0a
---
src/video_output/snapshot.c | 39 +++++++++++++++++++++++++++++++++++----
src/video_output/snapshot.h | 14 +++-----------
src/video_output/video_output.c | 13 +++++++------
src/video_output/vout_internal.h | 5 +++--
src/video_output/vout_intf.c | 1 +
5 files changed, 49 insertions(+), 23 deletions(-)
diff --git a/src/video_output/snapshot.c b/src/video_output/snapshot.c
index 8d32ddad95..5dfde71261 100644
--- a/src/video_output/snapshot.c
+++ b/src/video_output/snapshot.c
@@ -41,18 +41,36 @@
#include "snapshot.h"
#include "vout_internal.h"
-/* */
-void vout_snapshot_Init(vout_snapshot_t *snap)
+struct vout_snapshot {
+ vlc_mutex_t lock;
+ vlc_cond_t wait;
+
+ bool is_available;
+ int request_count;
+ picture_t *picture;
+
+};
+
+vout_snapshot_t *vout_snapshot_New(void)
{
+ vout_snapshot_t *snap = malloc(sizeof (*snap));
+ if (unlikely(snap == NULL))
+ return NULL;
+
vlc_mutex_init(&snap->lock);
vlc_cond_init(&snap->wait);
snap->is_available = true;
snap->request_count = 0;
snap->picture = NULL;
+ return snap;
}
-void vout_snapshot_Clean(vout_snapshot_t *snap)
+
+void vout_snapshot_Destroy(vout_snapshot_t *snap)
{
+ if (snap == NULL)
+ return;
+
picture_t *picture = snap->picture;
while (picture) {
picture_t *next = picture->p_next;
@@ -62,10 +80,14 @@ void vout_snapshot_Clean(vout_snapshot_t *snap)
vlc_cond_destroy(&snap->wait);
vlc_mutex_destroy(&snap->lock);
+ free(snap);
}
void vout_snapshot_End(vout_snapshot_t *snap)
{
+ if (snap == NULL)
+ return;
+
vlc_mutex_lock(&snap->lock);
snap->is_available = false;
@@ -77,6 +99,9 @@ void vout_snapshot_End(vout_snapshot_t *snap)
/* */
picture_t *vout_snapshot_Get(vout_snapshot_t *snap, vlc_tick_t timeout)
{
+ if (snap == NULL)
+ return NULL;
+
const vlc_tick_t deadline = vlc_tick_now() + timeout;
vlc_mutex_lock(&snap->lock);
@@ -100,9 +125,11 @@ picture_t *vout_snapshot_Get(vout_snapshot_t *snap, vlc_tick_t timeout)
return picture;
}
-/* */
bool vout_snapshot_IsRequested(vout_snapshot_t *snap)
{
+ if (snap == NULL)
+ return false;
+
bool has_request = false;
if (!vlc_mutex_trylock(&snap->lock)) {
has_request = snap->request_count > 0;
@@ -110,10 +137,14 @@ bool vout_snapshot_IsRequested(vout_snapshot_t *snap)
}
return has_request;
}
+
void vout_snapshot_Set(vout_snapshot_t *snap,
const video_format_t *fmt,
picture_t *picture)
{
+ if (snap == NULL)
+ return;
+
if (!fmt)
fmt = &picture->format;
diff --git a/src/video_output/snapshot.h b/src/video_output/snapshot.h
index 9b928d6cf0..cc16b7f29b 100644
--- a/src/video_output/snapshot.h
+++ b/src/video_output/snapshot.h
@@ -26,19 +26,11 @@
#include <vlc_picture.h>
-typedef struct {
- vlc_mutex_t lock;
- vlc_cond_t wait;
-
- bool is_available;
- int request_count;
- picture_t *picture;
-
-} vout_snapshot_t;
+typedef struct vout_snapshot vout_snapshot_t;
/* */
-void vout_snapshot_Init(vout_snapshot_t *);
-void vout_snapshot_Clean(vout_snapshot_t *);
+vout_snapshot_t *vout_snapshot_New(void);
+void vout_snapshot_Destroy(vout_snapshot_t *);
void vout_snapshot_End(vout_snapshot_t *);
diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c
index d00a7e2b71..2216bf78b8 100644
--- a/src/video_output/video_output.c
+++ b/src/video_output/video_output.c
@@ -52,6 +52,7 @@
#include "vout_internal.h"
#include "interlacing.h"
#include "display.h"
+#include "snapshot.h"
#include "window.h"
#include "../misc/variables.h"
@@ -144,7 +145,7 @@ static vout_thread_t *VoutCreate(vlc_object_t *object,
vout_control_Init(&vout->p->control);
vout_statistic_Init(&vout->p->statistic);
- vout_snapshot_Init(&vout->p->snapshot);
+ vout->p->snapshot = vout_snapshot_New();
vout_chrono_Init(&vout->p->render, 5, VLC_TICK_FROM_MS(10)); /* Arbitrary initial time */
/* Initialize locks */
@@ -270,7 +271,7 @@ void vout_Close(vout_thread_t *vout)
if (vout->p->input)
spu_Detach(vout->p->spu);
- vout_snapshot_End(&vout->p->snapshot);
+ vout_snapshot_End(vout->p->snapshot);
vout_control_PushVoid(&vout->p->control, VOUT_CONTROL_CLEAN);
vlc_join(vout->p->thread, NULL);
@@ -310,7 +311,7 @@ static void VoutDestructor(vlc_object_t *object)
vout_statistic_Clean(&vout->p->statistic);
/* */
- vout_snapshot_Clean(&vout->p->snapshot);
+ vout_snapshot_Destroy(vout->p->snapshot);
video_format_Clean(&vout->p->original);
}
@@ -469,7 +470,7 @@ int vout_GetSnapshot(vout_thread_t *vout,
video_format_t *fmt,
const char *type, vlc_tick_t timeout)
{
- picture_t *picture = vout_snapshot_Get(&vout->p->snapshot, timeout);
+ picture_t *picture = vout_snapshot_Get(vout->p->snapshot, timeout);
if (!picture) {
msg_Err(vout, "Failed to grab a snapshot");
return VLC_EGENERIC;
@@ -1042,7 +1043,7 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
/*
* Get the subpicture to be displayed
*/
- const bool do_snapshot = vout_snapshot_IsRequested(&sys->snapshot);
+ const bool do_snapshot = vout_snapshot_IsRequested(sys->snapshot);
vlc_tick_t render_subtitle_date;
if (sys->pause.is_on)
render_subtitle_date = sys->pause.date;
@@ -1182,7 +1183,7 @@ static int ThreadDisplayRenderPicture(vout_thread_t *vout, bool is_forced)
if (do_snapshot)
{
assert(snap_pic);
- vout_snapshot_Set(&sys->snapshot, &vd->source, snap_pic);
+ vout_snapshot_Set(sys->snapshot, &vd->source, snap_pic);
if (snap_pic != todisplay)
picture_Release(snap_pic);
}
diff --git a/src/video_output/vout_internal.h b/src/video_output/vout_internal.h
index b5b11c40f8..41f3e76484 100644
--- a/src/video_output/vout_internal.h
+++ b/src/video_output/vout_internal.h
@@ -29,7 +29,6 @@
#include <vlc_picture_pool.h>
#include <vlc_vout_display.h>
#include "vout_wrapper.h"
-#include "snapshot.h"
#include "statistic.h"
#include "chrono.h"
@@ -53,6 +52,8 @@ typedef struct {
} vout_configuration_t;
#include "control.h"
+struct vout_snapshot;
+
/* */
struct vout_thread_sys_t
{
@@ -67,7 +68,7 @@ struct vout_thread_sys_t
unsigned dpb_size;
/* Snapshot interface */
- vout_snapshot_t snapshot;
+ struct vout_snapshot *snapshot;
/* Statistics */
vout_statistic_t statistic;
diff --git a/src/video_output/vout_intf.c b/src/video_output/vout_intf.c
index e059030f8a..d41dff7063 100644
--- a/src/video_output/vout_intf.c
+++ b/src/video_output/vout_intf.c
@@ -42,6 +42,7 @@
#include <vlc_strings.h>
#include <vlc_charset.h>
#include "vout_internal.h"
+#include "snapshot.h"
/*****************************************************************************
* Local prototypes
More information about the vlc-commits
mailing list