dshow.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * Directshow capture interface
  3. * Copyright (c) 2010 Ramiro Polla
  4. *
  5. * This file is part of FFmpeg.
  6. *
  7. * FFmpeg is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * FFmpeg is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with FFmpeg; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #include "libavformat/timefilter.h"
  22. #include "avdevice.h"
  23. #include "dshow.h"
  24. struct dshow_ctx {
  25. IGraphBuilder *graph;
  26. char *device_name[2];
  27. IBaseFilter *device_filter[2];
  28. IPin *device_pin[2];
  29. libAVFilter *capture_filter[2];
  30. libAVPin *capture_pin[2];
  31. HANDLE mutex;
  32. HANDLE event;
  33. AVPacketList *pktl;
  34. unsigned int curbufsize;
  35. unsigned int video_frame_num;
  36. IMediaControl *control;
  37. TimeFilter *timefilter;
  38. };
  39. static enum PixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount)
  40. {
  41. switch(biCompression) {
  42. case MKTAG('U', 'Y', 'V', 'Y'):
  43. return PIX_FMT_UYVY422;
  44. case MKTAG('Y', 'U', 'Y', '2'):
  45. return PIX_FMT_YUYV422;
  46. case MKTAG('I', '4', '2', '0'):
  47. return PIX_FMT_YUV420P;
  48. case BI_RGB:
  49. switch(biBitCount) { /* 1-8 are untested */
  50. case 1:
  51. return PIX_FMT_MONOWHITE;
  52. case 4:
  53. return PIX_FMT_RGB4;
  54. case 8:
  55. return PIX_FMT_RGB8;
  56. case 16:
  57. return PIX_FMT_RGB555;
  58. case 24:
  59. return PIX_FMT_BGR24;
  60. case 32:
  61. return PIX_FMT_RGB32;
  62. }
  63. }
  64. return PIX_FMT_NONE;
  65. }
  66. static enum CodecID dshow_codecid(DWORD biCompression)
  67. {
  68. switch(biCompression) {
  69. case MKTAG('d', 'v', 's', 'd'):
  70. return CODEC_ID_DVVIDEO;
  71. case MKTAG('M', 'J', 'P', 'G'):
  72. case MKTAG('m', 'j', 'p', 'g'):
  73. return CODEC_ID_MJPEG;
  74. }
  75. return CODEC_ID_NONE;
  76. }
  77. static int
  78. dshow_read_close(AVFormatContext *s)
  79. {
  80. struct dshow_ctx *ctx = s->priv_data;
  81. AVPacketList *pktl;
  82. if (ctx->control) {
  83. IMediaControl_Stop(ctx->control);
  84. IMediaControl_Release(ctx->control);
  85. }
  86. if (ctx->graph)
  87. IGraphBuilder_Release(ctx->graph);
  88. /* FIXME remove filters from graph */
  89. /* FIXME disconnect pins */
  90. if (ctx->capture_pin[VideoDevice])
  91. libAVPin_Release(ctx->capture_pin[VideoDevice]);
  92. if (ctx->capture_pin[AudioDevice])
  93. libAVPin_Release(ctx->capture_pin[AudioDevice]);
  94. if (ctx->capture_filter[VideoDevice])
  95. libAVFilter_Release(ctx->capture_filter[VideoDevice]);
  96. if (ctx->capture_filter[AudioDevice])
  97. libAVFilter_Release(ctx->capture_filter[AudioDevice]);
  98. if (ctx->device_pin[VideoDevice])
  99. IPin_Release(ctx->device_pin[VideoDevice]);
  100. if (ctx->device_pin[AudioDevice])
  101. IPin_Release(ctx->device_pin[AudioDevice]);
  102. if (ctx->device_filter[VideoDevice])
  103. IBaseFilter_Release(ctx->device_filter[VideoDevice]);
  104. if (ctx->device_filter[AudioDevice])
  105. IBaseFilter_Release(ctx->device_filter[AudioDevice]);
  106. if (ctx->device_name[0])
  107. av_free(ctx->device_name[0]);
  108. if (ctx->device_name[1])
  109. av_free(ctx->device_name[1]);
  110. if(ctx->mutex)
  111. CloseHandle(ctx->mutex);
  112. if(ctx->event)
  113. CloseHandle(ctx->event);
  114. pktl = ctx->pktl;
  115. while (pktl) {
  116. AVPacketList *next = pktl->next;
  117. av_destruct_packet(&pktl->pkt);
  118. av_free(pktl);
  119. pktl = next;
  120. }
  121. return 0;
  122. }
  123. static char *dup_wchar_to_utf8(wchar_t *w)
  124. {
  125. char *s = NULL;
  126. int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0);
  127. s = av_malloc(l);
  128. if (s)
  129. WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0);
  130. return s;
  131. }
  132. static int shall_we_drop(AVFormatContext *s)
  133. {
  134. struct dshow_ctx *ctx = s->priv_data;
  135. const uint8_t dropscore[] = {62, 75, 87, 100};
  136. const int ndropscores = FF_ARRAY_ELEMS(dropscore);
  137. unsigned int buffer_fullness = (ctx->curbufsize*100)/s->max_picture_buffer;
  138. if(dropscore[++ctx->video_frame_num%ndropscores] <= buffer_fullness) {
  139. av_log(s, AV_LOG_ERROR,
  140. "real-time buffer %d%% full! frame dropped!\n", buffer_fullness);
  141. return 1;
  142. }
  143. return 0;
  144. }
  145. static void
  146. callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time)
  147. {
  148. AVFormatContext *s = priv_data;
  149. struct dshow_ctx *ctx = s->priv_data;
  150. AVPacketList **ppktl, *pktl_next;
  151. // dump_videohdr(s, vdhdr);
  152. if(shall_we_drop(s))
  153. return;
  154. WaitForSingleObject(ctx->mutex, INFINITE);
  155. pktl_next = av_mallocz(sizeof(AVPacketList));
  156. if(!pktl_next)
  157. goto fail;
  158. if(av_new_packet(&pktl_next->pkt, buf_size) < 0) {
  159. av_free(pktl_next);
  160. goto fail;
  161. }
  162. pktl_next->pkt.stream_index = index;
  163. pktl_next->pkt.pts = time;
  164. memcpy(pktl_next->pkt.data, buf, buf_size);
  165. for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next);
  166. *ppktl = pktl_next;
  167. ctx->curbufsize += buf_size;
  168. SetEvent(ctx->event);
  169. ReleaseMutex(ctx->mutex);
  170. return;
  171. fail:
  172. ReleaseMutex(ctx->mutex);
  173. return;
  174. }
  175. static int
  176. dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum,
  177. enum dshowDeviceType devtype)
  178. {
  179. struct dshow_ctx *ctx = avctx->priv_data;
  180. IBaseFilter *device_filter = NULL;
  181. IEnumMoniker *classenum = NULL;
  182. IGraphBuilder *graph = ctx->graph;
  183. IEnumPins *pins = 0;
  184. IMoniker *m = NULL;
  185. IPin *device_pin = NULL;
  186. libAVPin *capture_pin = NULL;
  187. libAVFilter *capture_filter = NULL;
  188. const char *device_name = ctx->device_name[devtype];
  189. int ret = AVERROR(EIO);
  190. IPin *pin;
  191. int r, i;
  192. const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory,
  193. &CLSID_AudioInputDeviceCategory };
  194. const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio };
  195. const char *devtypename = (devtype == VideoDevice) ? "video" : "audio";
  196. const wchar_t *filter_name[2] = { L"Audio capture filter", L"Video capture filter" };
  197. r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype],
  198. (IEnumMoniker **) &classenum, 0);
  199. if (r != S_OK) {
  200. av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices.\n",
  201. devtypename);
  202. goto error;
  203. }
  204. while (IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK && !device_filter) {
  205. IPropertyBag *bag = NULL;
  206. char *buf = NULL;
  207. VARIANT var;
  208. r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag);
  209. if (r != S_OK)
  210. goto fail1;
  211. var.vt = VT_BSTR;
  212. r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL);
  213. if (r != S_OK)
  214. goto fail1;
  215. buf = dup_wchar_to_utf8(var.bstrVal);
  216. if (strcmp(device_name, buf))
  217. goto fail1;
  218. IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter);
  219. fail1:
  220. if (buf)
  221. av_free(buf);
  222. if (bag)
  223. IPropertyBag_Release(bag);
  224. IMoniker_Release(m);
  225. }
  226. if (!device_filter) {
  227. av_log(avctx, AV_LOG_ERROR, "Could not find %s device.\n",
  228. devtypename);
  229. goto error;
  230. }
  231. ctx->device_filter [devtype] = device_filter;
  232. r = IGraphBuilder_AddFilter(graph, device_filter, NULL);
  233. if (r != S_OK) {
  234. av_log(avctx, AV_LOG_ERROR, "Could not add device filter to graph.\n");
  235. goto error;
  236. }
  237. r = IBaseFilter_EnumPins(device_filter, &pins);
  238. if (r != S_OK) {
  239. av_log(avctx, AV_LOG_ERROR, "Could not enumerate pins.\n");
  240. goto error;
  241. }
  242. i = 0;
  243. while (IEnumPins_Next(pins, 1, &pin, NULL) == S_OK && !device_pin) {
  244. IKsPropertySet *p = NULL;
  245. IEnumMediaTypes *types;
  246. PIN_INFO info = {0};
  247. AM_MEDIA_TYPE *type;
  248. GUID category;
  249. DWORD r2;
  250. IPin_QueryPinInfo(pin, &info);
  251. IBaseFilter_Release(info.pFilter);
  252. if (info.dir != PINDIR_OUTPUT)
  253. goto next;
  254. if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK)
  255. goto next;
  256. if (IKsPropertySet_Get(p, &AMPROPSETID_Pin, AMPROPERTY_PIN_CATEGORY,
  257. NULL, 0, &category, sizeof(GUID), &r2) != S_OK)
  258. goto next;
  259. if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE))
  260. goto next;
  261. if (IPin_EnumMediaTypes(pin, &types) != S_OK)
  262. goto next;
  263. IEnumMediaTypes_Reset(types);
  264. while (IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK && !device_pin) {
  265. if (IsEqualGUID(&type->majortype, mediatype[devtype])) {
  266. device_pin = pin;
  267. goto next;
  268. }
  269. CoTaskMemFree(type);
  270. }
  271. next:
  272. if (types)
  273. IEnumMediaTypes_Release(types);
  274. if (p)
  275. IKsPropertySet_Release(p);
  276. if (device_pin != pin)
  277. IPin_Release(pin);
  278. }
  279. if (!device_pin) {
  280. av_log(avctx, AV_LOG_ERROR,
  281. "Could not find output pin from %s capture device.\n", devtypename);
  282. goto error;
  283. }
  284. ctx->device_pin[devtype] = device_pin;
  285. capture_filter = libAVFilter_Create(avctx, callback, devtype);
  286. if (!capture_filter) {
  287. av_log(avctx, AV_LOG_ERROR, "Could not create grabber filter.\n");
  288. goto error;
  289. }
  290. ctx->capture_filter[devtype] = capture_filter;
  291. r = IGraphBuilder_AddFilter(graph, (IBaseFilter *) capture_filter,
  292. filter_name[devtype]);
  293. if (r != S_OK) {
  294. av_log(avctx, AV_LOG_ERROR, "Could not add capture filter to graph\n");
  295. goto error;
  296. }
  297. libAVPin_AddRef(capture_filter->pin);
  298. capture_pin = capture_filter->pin;
  299. ctx->capture_pin[devtype] = capture_pin;
  300. r = IGraphBuilder_ConnectDirect(graph, device_pin, (IPin *) capture_pin, NULL);
  301. if (r != S_OK) {
  302. av_log(avctx, AV_LOG_ERROR, "Could not connect pins\n");
  303. goto error;
  304. }
  305. ret = 0;
  306. error:
  307. if (pins)
  308. IEnumPins_Release(pins);
  309. if (classenum)
  310. IEnumMoniker_Release(classenum);
  311. return ret;
  312. }
  313. static enum CodecID waveform_codec_id(enum AVSampleFormat sample_fmt)
  314. {
  315. switch (sample_fmt) {
  316. case AV_SAMPLE_FMT_U8: return CODEC_ID_PCM_U8;
  317. case AV_SAMPLE_FMT_S16: return CODEC_ID_PCM_S16LE;
  318. case AV_SAMPLE_FMT_S32: return CODEC_ID_PCM_S32LE;
  319. default: return CODEC_ID_NONE; /* Should never happen. */
  320. }
  321. }
  322. static enum SampleFormat sample_fmt_bits_per_sample(int bits)
  323. {
  324. switch (bits) {
  325. case 8: return AV_SAMPLE_FMT_U8;
  326. case 16: return AV_SAMPLE_FMT_S16;
  327. case 32: return AV_SAMPLE_FMT_S32;
  328. default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */
  329. }
  330. }
  331. static int
  332. dshow_add_device(AVFormatContext *avctx, AVFormatParameters *ap,
  333. enum dshowDeviceType devtype)
  334. {
  335. struct dshow_ctx *ctx = avctx->priv_data;
  336. AM_MEDIA_TYPE type;
  337. AVCodecContext *codec;
  338. AVStream *st;
  339. int ret = AVERROR(EIO);
  340. st = av_new_stream(avctx, devtype);
  341. if (!st) {
  342. ret = AVERROR(ENOMEM);
  343. goto error;
  344. }
  345. ctx->capture_filter[devtype]->stream_index = st->index;
  346. libAVPin_ConnectionMediaType(ctx->capture_pin[devtype], &type);
  347. codec = st->codec;
  348. if (devtype == VideoDevice) {
  349. BITMAPINFOHEADER *bih = NULL;
  350. if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) {
  351. VIDEOINFOHEADER *v = (void *) type.pbFormat;
  352. bih = &v->bmiHeader;
  353. } else if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo2)) {
  354. VIDEOINFOHEADER2 *v = (void *) type.pbFormat;
  355. bih = &v->bmiHeader;
  356. }
  357. if (!bih) {
  358. av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n");
  359. goto error;
  360. }
  361. codec->time_base = ap->time_base;
  362. codec->codec_type = AVMEDIA_TYPE_VIDEO;
  363. codec->width = bih->biWidth;
  364. codec->height = bih->biHeight;
  365. codec->pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount);
  366. if (codec->pix_fmt == PIX_FMT_NONE) {
  367. codec->codec_id = dshow_codecid(bih->biCompression);
  368. if (codec->codec_id == CODEC_ID_NONE) {
  369. av_log(avctx, AV_LOG_ERROR, "Unknown compression type. "
  370. "Please report verbose (-v 9) debug information.\n");
  371. dshow_read_close(avctx);
  372. return AVERROR_PATCHWELCOME;
  373. }
  374. codec->bits_per_coded_sample = bih->biBitCount;
  375. } else {
  376. codec->codec_id = CODEC_ID_RAWVIDEO;
  377. if (bih->biCompression == BI_RGB) {
  378. codec->bits_per_coded_sample = bih->biBitCount;
  379. codec->extradata = av_malloc(9 + FF_INPUT_BUFFER_PADDING_SIZE);
  380. if (codec->extradata) {
  381. codec->extradata_size = 9;
  382. memcpy(codec->extradata, "BottomUp", 9);
  383. }
  384. }
  385. }
  386. } else {
  387. WAVEFORMATEX *fx = NULL;
  388. if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) {
  389. fx = (void *) type.pbFormat;
  390. }
  391. if (!fx) {
  392. av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n");
  393. goto error;
  394. }
  395. codec->codec_type = AVMEDIA_TYPE_AUDIO;
  396. codec->sample_fmt = sample_fmt_bits_per_sample(fx->wBitsPerSample);
  397. codec->codec_id = waveform_codec_id(codec->sample_fmt);
  398. codec->sample_rate = fx->nSamplesPerSec;
  399. codec->channels = fx->nChannels;
  400. }
  401. av_set_pts_info(st, 64, 1, 10000000);
  402. ret = 0;
  403. error:
  404. return ret;
  405. }
  406. static int parse_device_name(AVFormatContext *avctx)
  407. {
  408. struct dshow_ctx *ctx = avctx->priv_data;
  409. char **device_name = ctx->device_name;
  410. char *name = av_strdup(avctx->filename);
  411. char *tmp = name;
  412. int ret = 1;
  413. char *type;
  414. while ((type = strtok(tmp, "="))) {
  415. char *token = strtok(NULL, ":");
  416. tmp = NULL;
  417. if (!strcmp(type, "video")) {
  418. device_name[0] = token;
  419. } else if (!strcmp(type, "audio")) {
  420. device_name[1] = token;
  421. } else {
  422. device_name[0] = NULL;
  423. device_name[1] = NULL;
  424. break;
  425. }
  426. }
  427. if (!device_name[0] && !device_name[1]) {
  428. ret = 0;
  429. } else {
  430. if (device_name[0])
  431. device_name[0] = av_strdup(device_name[0]);
  432. if (device_name[1])
  433. device_name[1] = av_strdup(device_name[1]);
  434. }
  435. av_free(name);
  436. return ret;
  437. }
  438. static int dshow_read_header(AVFormatContext *avctx, AVFormatParameters *ap)
  439. {
  440. struct dshow_ctx *ctx = avctx->priv_data;
  441. IGraphBuilder *graph = NULL;
  442. ICreateDevEnum *devenum = NULL;
  443. IMediaControl *control = NULL;
  444. int ret = AVERROR(EIO);
  445. int r;
  446. if (!parse_device_name(avctx)) {
  447. av_log(avctx, AV_LOG_ERROR, "Malformed dshow input string.\n");
  448. goto error;
  449. }
  450. CoInitialize(0);
  451. r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,
  452. &IID_IGraphBuilder, (void **) &graph);
  453. if (r != S_OK) {
  454. av_log(avctx, AV_LOG_ERROR, "Could not create capture graph.\n");
  455. goto error;
  456. }
  457. ctx->graph = graph;
  458. r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER,
  459. &IID_ICreateDevEnum, (void **) &devenum);
  460. if (r != S_OK) {
  461. av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n");
  462. goto error;
  463. }
  464. if (ctx->device_name[VideoDevice]) {
  465. ret = dshow_open_device(avctx, devenum, VideoDevice);
  466. if (ret < 0)
  467. goto error;
  468. ret = dshow_add_device(avctx, ap, VideoDevice);
  469. if (ret < 0)
  470. goto error;
  471. }
  472. if (ctx->device_name[AudioDevice]) {
  473. ret = dshow_open_device(avctx, devenum, AudioDevice);
  474. if (ret < 0)
  475. goto error;
  476. ret = dshow_add_device(avctx, ap, AudioDevice);
  477. if (ret < 0)
  478. goto error;
  479. }
  480. ctx->mutex = CreateMutex(NULL, 0, NULL);
  481. if (!ctx->mutex) {
  482. av_log(avctx, AV_LOG_ERROR, "Could not create Mutex\n");
  483. goto error;
  484. }
  485. ctx->event = CreateEvent(NULL, 1, 0, NULL);
  486. if (!ctx->event) {
  487. av_log(avctx, AV_LOG_ERROR, "Could not create Event\n");
  488. goto error;
  489. }
  490. r = IGraphBuilder_QueryInterface(graph, &IID_IMediaControl, (void **) &control);
  491. if (r != S_OK) {
  492. av_log(avctx, AV_LOG_ERROR, "Could not get media control.\n");
  493. goto error;
  494. }
  495. ctx->control = control;
  496. r = IMediaControl_Run(control);
  497. if (r == S_FALSE) {
  498. OAFilterState pfs;
  499. r = IMediaControl_GetState(control, 0, &pfs);
  500. }
  501. if (r != S_OK) {
  502. av_log(avctx, AV_LOG_ERROR, "Could not run filter\n");
  503. goto error;
  504. }
  505. ret = 0;
  506. error:
  507. if (ret < 0)
  508. dshow_read_close(avctx);
  509. if (devenum)
  510. ICreateDevEnum_Release(devenum);
  511. return ret;
  512. }
  513. static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt)
  514. {
  515. struct dshow_ctx *ctx = s->priv_data;
  516. AVPacketList *pktl = NULL;
  517. while (!pktl) {
  518. WaitForSingleObject(ctx->mutex, INFINITE);
  519. pktl = ctx->pktl;
  520. if (ctx->pktl) {
  521. *pkt = ctx->pktl->pkt;
  522. ctx->pktl = ctx->pktl->next;
  523. av_free(pktl);
  524. }
  525. ResetEvent(ctx->event);
  526. ReleaseMutex(ctx->mutex);
  527. if (!pktl) {
  528. if (s->flags & AVFMT_FLAG_NONBLOCK) {
  529. return AVERROR(EAGAIN);
  530. } else {
  531. WaitForSingleObject(ctx->event, INFINITE);
  532. }
  533. }
  534. }
  535. ctx->curbufsize -= pkt->size;
  536. return pkt->size;
  537. }
  538. AVInputFormat ff_dshow_demuxer = {
  539. "dshow",
  540. NULL_IF_CONFIG_SMALL("DirectShow capture"),
  541. sizeof(struct dshow_ctx),
  542. NULL,
  543. dshow_read_header,
  544. dshow_read_packet,
  545. dshow_read_close,
  546. .flags = AVFMT_NOFILE,
  547. };