libavdevice/dshow_enummediatypes.c
Go to the documentation of this file.
00001 /*
00002  * DirectShow capture interface
00003  * Copyright (c) 2010 Ramiro Polla
00004  *
00005  * This file is part of FFmpeg.
00006  *
00007  * FFmpeg is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * FFmpeg is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with FFmpeg; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00020  */
00021 
00022 #include "dshow.h"
00023 
00024 DECLARE_QUERYINTERFACE(libAVEnumMediaTypes,
00025     { {&IID_IUnknown,0}, {&IID_IEnumPins,0} })
00026 DECLARE_ADDREF(libAVEnumMediaTypes)
00027 DECLARE_RELEASE(libAVEnumMediaTypes)
00028 
00029 long WINAPI
00030 libAVEnumMediaTypes_Next(libAVEnumMediaTypes *this, unsigned long n,
00031                          AM_MEDIA_TYPE **types, unsigned long *fetched)
00032 {
00033     int count = 0;
00034     dshowdebug("libAVEnumMediaTypes_Next(%p)\n", this);
00035     if (!types)
00036         return E_POINTER;
00037     if (!this->pos && n == 1) {
00038         if (!IsEqualGUID(&this->type.majortype, &GUID_NULL)) {
00039             AM_MEDIA_TYPE *type = av_malloc(sizeof(AM_MEDIA_TYPE));
00040             ff_copy_dshow_media_type(type, &this->type);
00041             *types = type;
00042             count = 1;
00043         }
00044         this->pos = 1;
00045     }
00046     if (fetched)
00047         *fetched = count;
00048     if (!count)
00049         return S_FALSE;
00050     return S_OK;
00051 }
00052 long WINAPI
00053 libAVEnumMediaTypes_Skip(libAVEnumMediaTypes *this, unsigned long n)
00054 {
00055     dshowdebug("libAVEnumMediaTypes_Skip(%p)\n", this);
00056     if (n) /* Any skip will always fall outside of the only valid type. */
00057         return S_FALSE;
00058     return S_OK;
00059 }
00060 long WINAPI
00061 libAVEnumMediaTypes_Reset(libAVEnumMediaTypes *this)
00062 {
00063     dshowdebug("libAVEnumMediaTypes_Reset(%p)\n", this);
00064     this->pos = 0;
00065     return S_OK;
00066 }
00067 long WINAPI
00068 libAVEnumMediaTypes_Clone(libAVEnumMediaTypes *this, libAVEnumMediaTypes **enums)
00069 {
00070     libAVEnumMediaTypes *new;
00071     dshowdebug("libAVEnumMediaTypes_Clone(%p)\n", this);
00072     if (!enums)
00073         return E_POINTER;
00074     new = libAVEnumMediaTypes_Create(&this->type);
00075     if (!new)
00076         return E_OUTOFMEMORY;
00077     new->pos = this->pos;
00078     *enums = new;
00079     return S_OK;
00080 }
00081 
00082 static int
00083 libAVEnumMediaTypes_Setup(libAVEnumMediaTypes *this, const AM_MEDIA_TYPE *type)
00084 {
00085     IEnumPinsVtbl *vtbl = this->vtbl;
00086     SETVTBL(vtbl, libAVEnumMediaTypes, QueryInterface);
00087     SETVTBL(vtbl, libAVEnumMediaTypes, AddRef);
00088     SETVTBL(vtbl, libAVEnumMediaTypes, Release);
00089     SETVTBL(vtbl, libAVEnumMediaTypes, Next);
00090     SETVTBL(vtbl, libAVEnumMediaTypes, Skip);
00091     SETVTBL(vtbl, libAVEnumMediaTypes, Reset);
00092     SETVTBL(vtbl, libAVEnumMediaTypes, Clone);
00093 
00094     if (!type) {
00095         this->type.majortype = GUID_NULL;
00096     } else {
00097         ff_copy_dshow_media_type(&this->type, type);
00098     }
00099 
00100     return 1;
00101 }
00102 DECLARE_CREATE(libAVEnumMediaTypes, libAVEnumMediaTypes_Setup(this, type), const AM_MEDIA_TYPE *type)
00103 DECLARE_DESTROY(libAVEnumMediaTypes, nothing)