dshow_enummediatypes.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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(libAVEnumMediaTypes,
  23. { {&IID_IUnknown,0}, {&IID_IEnumPins,0} })
  24. DECLARE_ADDREF(libAVEnumMediaTypes)
  25. DECLARE_RELEASE(libAVEnumMediaTypes)
  26. long WINAPI
  27. libAVEnumMediaTypes_Next(libAVEnumMediaTypes *this, unsigned long n,
  28. AM_MEDIA_TYPE **types, unsigned long *fetched)
  29. {
  30. int count = 0;
  31. dshowdebug("libAVEnumMediaTypes_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. ff_copy_dshow_media_type(type, &this->type);
  38. *types = type;
  39. count = 1;
  40. }
  41. this->pos = 1;
  42. }
  43. if (fetched)
  44. *fetched = count;
  45. if (!count)
  46. return S_FALSE;
  47. return S_OK;
  48. }
  49. long WINAPI
  50. libAVEnumMediaTypes_Skip(libAVEnumMediaTypes *this, unsigned long n)
  51. {
  52. dshowdebug("libAVEnumMediaTypes_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
  58. libAVEnumMediaTypes_Reset(libAVEnumMediaTypes *this)
  59. {
  60. dshowdebug("libAVEnumMediaTypes_Reset(%p)\n", this);
  61. this->pos = 0;
  62. return S_OK;
  63. }
  64. long WINAPI
  65. libAVEnumMediaTypes_Clone(libAVEnumMediaTypes *this, libAVEnumMediaTypes **enums)
  66. {
  67. libAVEnumMediaTypes *new;
  68. dshowdebug("libAVEnumMediaTypes_Clone(%p)\n", this);
  69. if (!enums)
  70. return E_POINTER;
  71. new = libAVEnumMediaTypes_Create(&this->type);
  72. if (!new)
  73. return E_OUTOFMEMORY;
  74. new->pos = this->pos;
  75. *enums = new;
  76. return S_OK;
  77. }
  78. static int
  79. libAVEnumMediaTypes_Setup(libAVEnumMediaTypes *this, const AM_MEDIA_TYPE *type)
  80. {
  81. IEnumPinsVtbl *vtbl = this->vtbl;
  82. SETVTBL(vtbl, libAVEnumMediaTypes, QueryInterface);
  83. SETVTBL(vtbl, libAVEnumMediaTypes, AddRef);
  84. SETVTBL(vtbl, libAVEnumMediaTypes, Release);
  85. SETVTBL(vtbl, libAVEnumMediaTypes, Next);
  86. SETVTBL(vtbl, libAVEnumMediaTypes, Skip);
  87. SETVTBL(vtbl, libAVEnumMediaTypes, Reset);
  88. SETVTBL(vtbl, libAVEnumMediaTypes, Clone);
  89. if (!type) {
  90. this->type.majortype = GUID_NULL;
  91. } else {
  92. ff_copy_dshow_media_type(&this->type, type);
  93. }
  94. return 1;
  95. }
  96. DECLARE_CREATE(libAVEnumMediaTypes, libAVEnumMediaTypes_Setup(this, type), const AM_MEDIA_TYPE *type)
  97. DECLARE_DESTROY(libAVEnumMediaTypes, nothing)