2 Copyright 2004-2005 Chris Tallon, Andreas Vogel
4 This file is part of VOMP.
6 VOMP is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 VOMP is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with VOMP; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "mediaplayer.h"
25 class MediaProviderHolder {
27 MediaProvider *provider;
30 MediaProviderHolder(MediaProvider *p,ULONG i, ULONG r=1) {
39 MediaPlayer::MediaPlayer(){}
40 MediaPlayer::~MediaPlayer(){
41 for (Tplist::iterator it=plist.begin();it<plist.end();it++) {
47 * get the root media list
48 * the returned list has to be destroyed by the caller
49 * if NULL is returned currently no media is available
51 MediaList* MediaPlayer::getRootList(){
52 Log::getInstance()->log("MediaPlayer::getRootList",Log::DEBUG,"numproviders %d",plist.size());
53 MediaList * rt=new MediaList(new MediaURI(0,NULL,NULL));
54 for (Tplist::iterator it=plist.begin();it<plist.end();it++) {
55 MediaList *cur=(*it)->provider->getRootList();
57 //we take the entries away from the list - so don't delete them with the list
58 cur->setOwning(false);
59 Log::getInstance()->log("MediaPlayer::getRootList",Log::DEBUG,"got list for provider %p with %d items",(*it),cur->size());
60 for (MediaList::iterator mi=cur->begin();mi<cur->end();mi++) {
62 //always set the URI in the root list because we combine entries
63 //from different lists
65 MediaURI *u=cur->getURI(m);
67 Log::getInstance()->log("MediaPlayer::getRootList",Log::DEBUG,"set uri n=%s,d=%s",u->getName(),u->getDisplayName());
71 Log::getInstance()->log("MediaPlayer::getRootList",Log::DEBUG,"added item to list name=%s",m->getFileName());
80 * get a medialist for a given parent
81 * the returned list has to be destroyed by the caller
82 * NULL if no entries found
84 MediaList* MediaPlayer::getMediaList(const MediaURI * parent){
85 Log::getInstance()->log("MediaPlayer::getMediaList",Log::DEBUG,"numproviders %d,parent=%p",plist.size(),parent);
86 MediaProvider *p=providerById(parent->getProvider());
90 return p->getMediaList(parent);
95 * afterwards getBlock or other functions must be possible
96 * currently only one medium is open at the same time
98 * @param channel: channel id, NUMCHANNELS must be supported
99 * @param xsize,ysize: size of the screen
100 * @param size out: the size of the medium
101 * @return != 0 in case of error
104 int MediaPlayer::openMedium(ULONG channel, const MediaURI * uri, ULLONG * size, ULONG xsize, ULONG ysize){
105 if ( channel >= NUMCHANNELS) return -1;
106 info[channel].provider=NULL;
108 MediaProvider *p=providerById(uri->getProvider());
112 int rt=p->openMedium(channel,uri,size,xsize,ysize);
114 info[channel].providerId=uri->getProvider();
115 info[channel].provider=p;
122 * get a block for a channel
123 * @param offset - the offset
124 * @param len - the required len
125 * @param outlen out - the read len if 0 this is EOF
126 * @param buffer out the allocated buffer (must be freed with free!)
127 * @return != 0 in case of error
129 int MediaPlayer::getMediaBlock(ULONG channel, ULLONG offset, ULONG len, ULONG * outlen,
130 unsigned char ** buffer) {
131 if ( channel >= NUMCHANNELS) return -1;
132 if ( info[channel].provider == NULL) return -1;
133 return info[channel].provider->getMediaBlock(channel,offset,len,outlen,buffer);
138 * close a media channel
140 int MediaPlayer::closeMediaChannel(ULONG channel){
141 if ( channel >= NUMCHANNELS) return -1;
142 if ( info[channel].provider == NULL) return -1;
143 int rt=info[channel].provider->closeMediaChannel(channel);
144 info[channel].provider=NULL;
145 info[channel].providerId=0;
150 * return the media info for a given channel
151 * return != 0 on error
152 * the caller has to provide a pointer to an existing media info
154 int MediaPlayer::getMediaInfo(ULONG channel, struct MediaInfo * result){
155 if ( channel >= NUMCHANNELS) return -1;
156 if ( info[channel].provider == NULL) return -1;
157 return info[channel].provider->getMediaInfo(channel,result);
162 void MediaPlayer::registerMediaProvider(MediaProvider *p,ULONG providerId,ULONG range) {
164 MediaProviderHolder *h=new MediaProviderHolder(p,providerId,range);
165 Log::getInstance()->log("MediaPlayer::registerMediaProvider",Log::DEBUG,"p=%p",p);
169 MediaProvider * MediaPlayer::providerById(ULONG id) {
170 MediaProvider *rt=NULL;
171 for (Tplist::iterator it=plist.begin();it<plist.end();it++) {
172 MediaProviderHolder *h=*it;
173 if (id >= h->id && id < (h->id+h->range)) {
178 Log::getInstance()->log("MediaPlayer::providerById",Log::DEBUG,"id=%d,p=%p",id,rt);
182 MediaPlayer* MediaPlayer::getInstance() {
183 return (MediaPlayer *) MediaPlayerRegister::getInstance();
186 MediaPlayerRegister* MediaPlayerRegister::getInstance() {
188 instance=new MediaPlayer();
192 MediaPlayerRegister *MediaPlayerRegister::instance=NULL;