dshow_enummediatypes.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 "libavutil/mem.h"
  22. #include "dshow_capture.h"
  23. DECLARE_QUERYINTERFACE(enummediatypes, DShowEnumMediaTypes,
  24. { {&IID_IUnknown,0}, {&IID_IEnumMediaTypes,0} })
  25. DECLARE_ADDREF(enummediatypes, DShowEnumMediaTypes)
  26. DECLARE_RELEASE(enummediatypes, DShowEnumMediaTypes)
  27. long WINAPI ff_dshow_enummediatypes_Next(DShowEnumMediaTypes *this, unsigned long n,
  28. AM_MEDIA_TYPE **types, unsigned long *fetched)
  29. {
  30. int count = 0;
  31. dshowdebug("ff_dshow_enummediatypes_Next(%p)\n", this);
  32. if (!types)
  33. return E_POINTER;
  34. if (!this->pos && n == 1) {
  35. if (!IsEqualGUID(&this->type.majortype, &GUID_NULL)) {
  36. AM_MEDIA_TYPE *type = av_malloc(sizeof(AM_MEDIA_TYPE));
  37. if (!type)
  38. return E_OUTOFMEMORY;
  39. ff_copy_dshow_media_type(type, &this->type);
  40. *types = type;
  41. count = 1;
  42. }
  43. this->pos = 1;
  44. }
  45. if (fetched)
  46. *fetched = count;
  47. if (!count)
  48. return S_FALSE;
  49. return S_OK;
  50. }
  51. long WINAPI ff_dshow_enummediatypes_Skip(DShowEnumMediaTypes *this, unsigned long n)
  52. {
  53. dshowdebug("ff_dshow_enummediatypes_Skip(%p)\n", this);
  54. if (n) /* Any skip will always fall outside of the only valid type. */
  55. return S_FALSE;
  56. return S_OK;
  57. }
  58. long WINAPI ff_dshow_enummediatypes_Reset(DShowEnumMediaTypes *this)
  59. {
  60. dshowdebug("ff_dshow_enummediatypes_Reset(%p)\n", this);
  61. this->pos = 0;
  62. return S_OK;
  63. }
  64. long WINAPI ff_dshow_enummediatypes_Clone(DShowEnumMediaTypes *this, DShowEnumMediaTypes **enums)
  65. {
  66. DShowEnumMediaTypes *new;
  67. dshowdebug("ff_dshow_enummediatypes_Clone(%p)\n", this);
  68. if (!enums)
  69. return E_POINTER;
  70. new = ff_dshow_enummediatypes_Create(&this->type);
  71. if (!new)
  72. return E_OUTOFMEMORY;
  73. new->pos = this->pos;
  74. *enums = new;
  75. return S_OK;
  76. }
  77. static int ff_dshow_enummediatypes_Setup(DShowEnumMediaTypes *this, const AM_MEDIA_TYPE *type)
  78. {
  79. IEnumMediaTypesVtbl *vtbl = this->vtbl;
  80. SETVTBL(vtbl, enummediatypes, QueryInterface);
  81. SETVTBL(vtbl, enummediatypes, AddRef);
  82. SETVTBL(vtbl, enummediatypes, Release);
  83. SETVTBL(vtbl, enummediatypes, Next);
  84. SETVTBL(vtbl, enummediatypes, Skip);
  85. SETVTBL(vtbl, enummediatypes, Reset);
  86. SETVTBL(vtbl, enummediatypes, Clone);
  87. if (!type) {
  88. this->type.majortype = GUID_NULL;
  89. } else {
  90. ff_copy_dshow_media_type(&this->type, type);
  91. }
  92. return 1;
  93. }
  94. DECLARE_CREATE(enummediatypes, DShowEnumMediaTypes, ff_dshow_enummediatypes_Setup(this, type), const AM_MEDIA_TYPE *type)
  95. DECLARE_DESTROY(enummediatypes, DShowEnumMediaTypes, nothing)