dshow_enummediatypes.c 3.4 KB

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