History

avdevice/decklink: remove pthread dependency

Purpose: avdevice/decklink: Removed pthread dependency by replacing semaphore used in code appropriately. Doing so makes it easier to build ffmpeg using Visual C++ on Windows. This is a contination of Kyle Schwarz's "avdevice/decklink: Remove pthread dependency" patch that is available at https://patchwork.ffmpeg.org/patch/2654/ . This patch wasn't accepted, and as far as I can tell, there was no follow-up after it was rejected. Notes: Used Visual Studio 2015 (with update 3) for this. Comments: -- configure: Eliminated pthreads dependency for decklink_indev_deps and decklink_outdev_deps and replaced with threads dependency -- libavdevice/decklink_common.cpp / .h: a) Eliminated semaphore and replaced with a combination of a mutex, condition variable, and a counter (frames_buffer_available_spots). b) Removed include of pthread.h and semaphore.h and now using libavutil/thread.h instead. -- libavdevice/decklink_dec.cpp: Eliminated include of pthread.h and semaphore.h. -- libavdevice/decklink_enc.cpp: a) Eliminated include of pthread.h and semaphore.h. b) Replaced use of semaphore with the equivalent using a combination of a mutex, condition variable, and a counter (frames_buffer_available_spots). In theory, libavutil/thread.h and the associated code could have been modified instead to add cross-platform implementations of the sem_ functions, but an inspection of the ffmpeg source base indicates that there are only two cases in which semaphores are used (including this one that was replaced), so it was deemed to not be worth the effort.

Aaron Levinson committed 9 years ago

Commit 9e86a611 parent e8547645 files · +21 −17Browse files

Unified · Split

5 files
  1. configure +2 −2
  2. libavdevice/decklink_common.cpp +0 −3
  3. libavdevice/decklink_common.h +4 −1
  4. libavdevice/decklink_dec.cpp +0 −3
  5. libavdevice/decklink_enc.cpp +15 −8
configure+2−2
@@ -2995,9 +2995,9 @@ avfoundation_indev_deps="pthreads" · 2994 unmodified lines
2995avfoundation_indev_extralibs="-framework Foundation -framework AVFoundation -framework CoreVideo -framework CoreMedia"2995avfoundation_indev_extralibs="-framework Foundation -framework AVFoundation -framework CoreVideo -framework CoreMedia"
2996bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"2996bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h"
2997caca_outdev_deps="libcaca"2997caca_outdev_deps="libcaca"
2998decklink_indev_deps="decklink pthreads"2998decklink_indev_deps="decklink threads"
2999decklink_indev_extralibs="-lstdc++"2999decklink_indev_extralibs="-lstdc++"
3000decklink_outdev_deps="decklink pthreads"3000decklink_outdev_deps="decklink threads"
3001decklink_outdev_extralibs="-lstdc++"3001decklink_outdev_extralibs="-lstdc++"
3002dshow_indev_deps="IBaseFilter"3002dshow_indev_deps="IBaseFilter"
3003dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid -loleaut32 -lshlwapi"3003dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid -loleaut32 -lshlwapi"
libavdevice/decklink_common.cpp+0−3
@@ -26,9 +26,6 @@ · 25 unmodified lines
26#include <DeckLinkAPIDispatch.cpp>26#include <DeckLinkAPIDispatch.cpp>
27#endif27#endif
28 28
29#include <pthread.h>
30#include <semaphore.h>
31
32extern "C" {29extern "C" {
33#include "libavformat/avformat.h"30#include "libavformat/avformat.h"
34#include "libavformat/internal.h"31#include "libavformat/internal.h"
libavdevice/decklink_common.h+4−1
@@ -24,6 +24,7 @@ · 23 unmodified lines
24 24
25#include <DeckLinkAPIVersion.h>25#include <DeckLinkAPIVersion.h>
26 26
27#include "libavutil/thread.h"
27#include "decklink_common_c.h"28#include "decklink_common_c.h"
28 29
29class decklink_output_callback;30class decklink_output_callback;
@@ -89,7 +90,9 @@ struct decklink_ctx { · 59 unmodified lines
89 int frames_preroll;90 int frames_preroll;
90 int frames_buffer;91 int frames_buffer;
91 92
92 sem_t semaphore;93 pthread_mutex_t mutex;
94 pthread_cond_t cond;
95 int frames_buffer_available_spots;
93 96
94 int channels;97 int channels;
95};98};
libavdevice/decklink_dec.cpp+0−3
@@ -21,9 +21,6 @@ · 20 unmodified lines
21 21
22#include <DeckLinkAPI.h>22#include <DeckLinkAPI.h>
23 23
24#include <pthread.h>
25#include <semaphore.h>
26
27extern "C" {24extern "C" {
28#include "config.h"25#include "config.h"
29#include "libavformat/avformat.h"26#include "libavformat/avformat.h"
libavdevice/decklink_enc.cpp+15−8
@@ -24,9 +24,6 @@ using std::atomic; · 23 unmodified lines
24 24
25#include <DeckLinkAPI.h>25#include <DeckLinkAPI.h>
26 26
27#include <pthread.h>
28#include <semaphore.h>
29
30extern "C" {27extern "C" {
31#include "libavformat/avformat.h"28#include "libavformat/avformat.h"
32#include "libavformat/internal.h"29#include "libavformat/internal.h"
@@ -91,7 +88,10 @@ public: · 58 unmodified lines
91 88
92 av_frame_unref(avframe);89 av_frame_unref(avframe);
93 90
94 sem_post(&ctx->semaphore);91 pthread_mutex_lock(&ctx->mutex);
92 ctx->frames_buffer_available_spots++;
93 pthread_cond_broadcast(&ctx->cond);
94 pthread_mutex_unlock(&ctx->mutex);
95 95
96 return S_OK;96 return S_OK;
97 }97 }
@@ -133,7 +133,6 @@ static int decklink_setup_video(AVFormatContext *avctx, AVStream *st) · 35 unmodified lines
133 ctx->output_callback = new decklink_output_callback();133 ctx->output_callback = new decklink_output_callback();
134 ctx->dlo->SetScheduledFrameCompletionCallback(ctx->output_callback);134 ctx->dlo->SetScheduledFrameCompletionCallback(ctx->output_callback);
135 135
136 /* Start video semaphore. */
137 ctx->frames_preroll = st->time_base.den * ctx->preroll;136 ctx->frames_preroll = st->time_base.den * ctx->preroll;
138 if (st->time_base.den > 1000)137 if (st->time_base.den > 1000)
139 ctx->frames_preroll /= 1000;138 ctx->frames_preroll /= 1000;
@@ -141,7 +140,9 @@ static int decklink_setup_video(AVFormatContext *avctx, AVStream *st) · 1 unmodified line
141 /* Buffer twice as many frames as the preroll. */140 /* Buffer twice as many frames as the preroll. */
142 ctx->frames_buffer = ctx->frames_preroll * 2;141 ctx->frames_buffer = ctx->frames_preroll * 2;
143 ctx->frames_buffer = FFMIN(ctx->frames_buffer, 60);142 ctx->frames_buffer = FFMIN(ctx->frames_buffer, 60);
144 sem_init(&ctx->semaphore, 0, ctx->frames_buffer);143 pthread_mutex_init(&ctx->mutex, NULL);
144 pthread_cond_init(&ctx->cond, NULL);
145 ctx->frames_buffer_available_spots = ctx->frames_buffer;
145 146
146 /* The device expects the framerate to be fixed. */147 /* The device expects the framerate to be fixed. */
147 avpriv_set_pts_info(st, 64, st->time_base.num, st->time_base.den);148 avpriv_set_pts_info(st, 64, st->time_base.num, st->time_base.den);
@@ -211,7 +212,8 @@ av_cold int ff_decklink_write_trailer(AVFormatContext *avctx) · 63 unmodified lines
211 if (ctx->output_callback)212 if (ctx->output_callback)
212 delete ctx->output_callback;213 delete ctx->output_callback;
213 214
214 sem_destroy(&ctx->semaphore);215 pthread_mutex_destroy(&ctx->mutex);
216 pthread_cond_destroy(&ctx->cond);
215 217
216 av_freep(&cctx->ctx);218 av_freep(&cctx->ctx);
217 219
@@ -247,7 +249,12 @@ static int decklink_write_video_packet(AVFormatContext *avctx, AVPacket *pkt) · 29 unmodified lines
247 }249 }
248 250
249 /* Always keep at most one second of frames buffered. */251 /* Always keep at most one second of frames buffered. */
250 sem_wait(&ctx->semaphore);252 pthread_mutex_lock(&ctx->mutex);
253 while (ctx->frames_buffer_available_spots == 0) {
254 pthread_cond_wait(&ctx->cond, &ctx->mutex);
255 }
256 ctx->frames_buffer_available_spots--;
257 pthread_mutex_unlock(&ctx->mutex);
251 258
252 /* Schedule frame for playback. */259 /* Schedule frame for playback. */
253 hr = ctx->dlo->ScheduleVideoFrame((struct IDeckLinkVideoFrame *) frame,260 hr = ctx->dlo->ScheduleVideoFrame((struct IDeckLinkVideoFrame *) frame,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t