[vlc-commits] omxil: split timestamp helper to re-useable header

Felix Paul Kühne git at videolan.org
Wed Jul 29 18:58:33 CEST 2015


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Wed Jul 29 18:54:47 2015 +0200| [d962b8260d939a35e7bfc7a36d27f7e76f554bea] | committer: Felix Paul Kühne

omxil: split timestamp helper to re-useable header

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=d962b8260d939a35e7bfc7a36d27f7e76f554bea
---

 include/vlc_timestamp_helper.h   |  101 ++++++++++++++++++++++++++++++++++++++
 modules/codec/omxil/mediacodec.c |   75 +---------------------------
 2 files changed, 102 insertions(+), 74 deletions(-)

diff --git a/include/vlc_timestamp_helper.h b/include/vlc_timestamp_helper.h
new file mode 100644
index 0000000..5e08c35
--- /dev/null
+++ b/include/vlc_timestamp_helper.h
@@ -0,0 +1,101 @@
+/*****************************************************************************
+ * vlc_timestamp_helper.h : timestamp handling helpers
+ *****************************************************************************
+ * Copyright (C) 2014 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Felix Abecassis <felix.abecassis at gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_TIMESTAMP_H
+#define VLC_TIMESTAMP_H 1
+
+/* Implementation of a circular buffer of timestamps with overwriting
+ * of older values. MediaCodec has only one type of timestamp, if a
+ * block has no PTS, we send the DTS instead. Some hardware decoders
+ * cannot cope with this situation and output the frames in the wrong
+ * order. As a workaround in this case, we use a FIFO of timestamps in
+ * order to remember which input packets had no PTS.  Since an
+ * hardware decoder can silently drop frames, this might cause a
+ * growing desynchronization with the actual timestamp. Thus the
+ * circular buffer has a limited size and will overwrite older values.
+ */
+typedef struct
+{
+    uint32_t          begin;
+    uint32_t          size;
+    uint32_t          capacity;
+    int64_t           *buffer;
+} timestamp_fifo_t;
+
+static inline timestamp_fifo_t *timestamp_FifoNew(uint32_t capacity)
+{
+    timestamp_fifo_t *fifo = calloc(1, sizeof(*fifo));
+    if (!fifo)
+        return NULL;
+    fifo->buffer = malloc(capacity * sizeof(*fifo->buffer));
+    if (!fifo->buffer) {
+        free(fifo);
+        return NULL;
+    }
+    fifo->capacity = capacity;
+    return fifo;
+}
+
+static inline void timestamp_FifoRelease(timestamp_fifo_t *fifo)
+{
+    free(fifo->buffer);
+    free(fifo);
+}
+
+static inline bool timestamp_FifoIsEmpty(timestamp_fifo_t *fifo)
+{
+    return fifo->size == 0;
+}
+
+static inline bool timestamp_FifoIsFull(timestamp_fifo_t *fifo)
+{
+    return fifo->size == fifo->capacity;
+}
+
+static inline void timestamp_FifoEmpty(timestamp_fifo_t *fifo)
+{
+    fifo->size = 0;
+}
+
+static inline void timestamp_FifoPut(timestamp_fifo_t *fifo, int64_t ts)
+{
+    uint32_t end = (fifo->begin + fifo->size) % fifo->capacity;
+    fifo->buffer[end] = ts;
+    if (!timestamp_FifoIsFull(fifo))
+        fifo->size += 1;
+    else
+        fifo->begin = (fifo->begin + 1) % fifo->capacity;
+}
+
+static inline int64_t timestamp_FifoGet(timestamp_fifo_t *fifo)
+{
+    if (timestamp_FifoIsEmpty(fifo))
+        return VLC_TS_INVALID;
+
+    int64_t result = fifo->buffer[fifo->begin];
+    fifo->begin = (fifo->begin + 1) % fifo->capacity;
+    fifo->size -= 1;
+    return result;
+}
+
+#endif
diff --git a/modules/codec/omxil/mediacodec.c b/modules/codec/omxil/mediacodec.c
index 97d082c..f9c7d1d 100644
--- a/modules/codec/omxil/mediacodec.c
+++ b/modules/codec/omxil/mediacodec.c
@@ -38,6 +38,7 @@
 #include <vlc_block_helper.h>
 #include <vlc_cpu.h>
 #include <vlc_memory.h>
+#include <vlc_timestamp_helper.h>
 
 #include "mediacodec.h"
 #include "../../packetizer/h264_nal.h"
@@ -51,80 +52,6 @@
 /* JNI functions to get/set an Android Surface object. */
 extern void jni_EventHardwareAccelerationError(); // TODO REMOVE
 
-/* Implementation of a circular buffer of timestamps with overwriting
- * of older values. MediaCodec has only one type of timestamp, if a
- * block has no PTS, we send the DTS instead. Some hardware decoders
- * cannot cope with this situation and output the frames in the wrong
- * order. As a workaround in this case, we use a FIFO of timestamps in
- * order to remember which input packets had no PTS.  Since an
- * hardware decoder can silently drop frames, this might cause a
- * growing desynchronization with the actual timestamp. Thus the
- * circular buffer has a limited size and will overwrite older values.
- */
-typedef struct
-{
-    uint32_t          begin;
-    uint32_t          size;
-    uint32_t          capacity;
-    int64_t           *buffer;
-} timestamp_fifo_t;
-
-static timestamp_fifo_t *timestamp_FifoNew(uint32_t capacity)
-{
-    timestamp_fifo_t *fifo = calloc(1, sizeof(*fifo));
-    if (!fifo)
-        return NULL;
-    fifo->buffer = malloc(capacity * sizeof(*fifo->buffer));
-    if (!fifo->buffer) {
-        free(fifo);
-        return NULL;
-    }
-    fifo->capacity = capacity;
-    return fifo;
-}
-
-static void timestamp_FifoRelease(timestamp_fifo_t *fifo)
-{
-    free(fifo->buffer);
-    free(fifo);
-}
-
-static bool timestamp_FifoIsEmpty(timestamp_fifo_t *fifo)
-{
-    return fifo->size == 0;
-}
-
-static bool timestamp_FifoIsFull(timestamp_fifo_t *fifo)
-{
-    return fifo->size == fifo->capacity;
-}
-
-static void timestamp_FifoEmpty(timestamp_fifo_t *fifo)
-{
-    fifo->size = 0;
-}
-
-static void timestamp_FifoPut(timestamp_fifo_t *fifo, int64_t ts)
-{
-    uint32_t end = (fifo->begin + fifo->size) % fifo->capacity;
-    fifo->buffer[end] = ts;
-    if (!timestamp_FifoIsFull(fifo))
-        fifo->size += 1;
-    else
-        fifo->begin = (fifo->begin + 1) % fifo->capacity;
-}
-
-static int64_t timestamp_FifoGet(timestamp_fifo_t *fifo)
-{
-    if (timestamp_FifoIsEmpty(fifo))
-        return VLC_TS_INVALID;
-
-    int64_t result = fifo->buffer[fifo->begin];
-    fifo->begin = (fifo->begin + 1) % fifo->capacity;
-    fifo->size -= 1;
-    return result;
-}
-
 /* Codec Specific Data */
 struct csd
 {



More information about the vlc-commits mailing list