1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
From 0a9f0aa8271b0fc18c7e9781e3d0bc215ba2fd02 Mon Sep 17 00:00:00 2001
From: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
Date: Thu, 1 Sep 2016 17:58:33 +0300
Subject: [PATCH 09/10] gstomxenc: move encoder disable code to separate
function
Signed-off-by: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
---
omx/gstomxvideoenc.c | 79 ++++++++++++++++++++++++++++----------------------
1 file changed, 45 insertions(+), 34 deletions(-)
diff --git a/omx/gstomxvideoenc.c b/omx/gstomxvideoenc.c
index 19a0eb9..6720648 100644
--- a/omx/gstomxvideoenc.c
+++ b/omx/gstomxvideoenc.c
@@ -1147,6 +1147,49 @@ gst_omx_video_enc_get_supported_colorformats (GstOMXVideoEnc * self)
}
static gboolean
+gst_omx_video_enc_disable(GstVideoEncoder * encoder)
+{
+ GstOMXVideoEnc *self;
+
+ self = GST_OMX_VIDEO_ENC (encoder);
+
+ GST_DEBUG_OBJECT (self, "Need to disable and drain encoder");
+ gst_omx_video_enc_drain (self, FALSE);
+ gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, TRUE);
+
+ /* Wait until the srcpad loop is finished,
+ * unlock GST_VIDEO_ENCODER_STREAM_LOCK to prevent deadlocks
+ * caused by using this lock from inside the loop function */
+ GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
+ gst_pad_stop_task (GST_VIDEO_ENCODER_SRC_PAD (encoder));
+ GST_VIDEO_ENCODER_STREAM_LOCK (self);
+
+ if (gst_omx_port_set_enabled (self->enc_in_port, FALSE) != OMX_ErrorNone)
+ return FALSE;
+ if (gst_omx_port_set_enabled (self->enc_out_port, FALSE) != OMX_ErrorNone)
+ return FALSE;
+ if (gst_omx_port_wait_buffers_released (self->enc_in_port,
+ 5 * GST_SECOND) != OMX_ErrorNone)
+ return FALSE;
+ if (gst_omx_port_wait_buffers_released (self->enc_out_port,
+ 1 * GST_SECOND) != OMX_ErrorNone)
+ return FALSE;
+ if (gst_omx_port_deallocate_buffers (self->enc_in_port) != OMX_ErrorNone)
+ return FALSE;
+ if (gst_omx_port_deallocate_buffers (self->enc_out_port) != OMX_ErrorNone)
+ return FALSE;
+ if (gst_omx_port_wait_enabled (self->enc_in_port,
+ 1 * GST_SECOND) != OMX_ErrorNone)
+ return FALSE;
+ if (gst_omx_port_wait_enabled (self->enc_out_port,
+ 1 * GST_SECOND) != OMX_ErrorNone)
+ return FALSE;
+
+ GST_DEBUG_OBJECT (self, "Encoder drained and disabled");
+ return TRUE;
+}
+
+static gboolean
gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
GstVideoCodecState * state)
{
@@ -1176,41 +1219,9 @@ gst_omx_video_enc_set_format (GstVideoEncoder * encoder,
* we have to disable the port and re-allocate all buffers. If no real
* format change happened we can just exit here.
*/
- if (needs_disable) {
- GST_DEBUG_OBJECT (self, "Need to disable and drain encoder");
- gst_omx_video_enc_drain (self, FALSE);
- gst_omx_port_set_flushing (self->enc_out_port, 5 * GST_SECOND, TRUE);
-
- /* Wait until the srcpad loop is finished,
- * unlock GST_VIDEO_ENCODER_STREAM_LOCK to prevent deadlocks
- * caused by using this lock from inside the loop function */
- GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
- gst_pad_stop_task (GST_VIDEO_ENCODER_SRC_PAD (encoder));
- GST_VIDEO_ENCODER_STREAM_LOCK (self);
-
- if (gst_omx_port_set_enabled (self->enc_in_port, FALSE) != OMX_ErrorNone)
+ if (needs_disable)
+ if (!gst_omx_video_enc_disable(encoder))
return FALSE;
- if (gst_omx_port_set_enabled (self->enc_out_port, FALSE) != OMX_ErrorNone)
- return FALSE;
- if (gst_omx_port_wait_buffers_released (self->enc_in_port,
- 5 * GST_SECOND) != OMX_ErrorNone)
- return FALSE;
- if (gst_omx_port_wait_buffers_released (self->enc_out_port,
- 1 * GST_SECOND) != OMX_ErrorNone)
- return FALSE;
- if (gst_omx_port_deallocate_buffers (self->enc_in_port) != OMX_ErrorNone)
- return FALSE;
- if (gst_omx_port_deallocate_buffers (self->enc_out_port) != OMX_ErrorNone)
- return FALSE;
- if (gst_omx_port_wait_enabled (self->enc_in_port,
- 1 * GST_SECOND) != OMX_ErrorNone)
- return FALSE;
- if (gst_omx_port_wait_enabled (self->enc_out_port,
- 1 * GST_SECOND) != OMX_ErrorNone)
- return FALSE;
-
- GST_DEBUG_OBJECT (self, "Encoder drained and disabled");
- }
negotiation_map = gst_omx_video_enc_get_supported_colorformats (self);
if (!negotiation_map) {
--
1.7.10.4
|