Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / content / media / video / src / nsChannelReader.cpp
blob2724df8b63b86de0f103b7302bfc0049e26c8970
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
3 /* ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
16 * The Original Code is Mozilla code.
18 * The Initial Developer of the Original Code is the Mozilla Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 2007
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Chris Double <chris.double@double.co.nz>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
38 #include "nsAString.h"
39 #include "nsThreadUtils.h"
40 #include "nsNetUtil.h"
41 #include "prlog.h"
42 #include "nsMediaDecoder.h"
43 #include "nsChannelReader.h"
44 #include "nsIScriptSecurityManager.h"
46 void nsChannelReader::Cancel()
48 mStream.Cancel();
51 PRUint32 nsChannelReader::Available()
53 return mStream.Available();
56 float nsChannelReader::DownloadRate()
58 return mStream.DownloadRate();
61 float nsChannelReader::PlaybackRate()
63 return mStream.PlaybackRate();
66 OggPlayErrorCode nsChannelReader::initialise(int aBlock)
68 return E_OGGPLAY_OK;
71 OggPlayErrorCode nsChannelReader::destroy()
73 mStream.Close();
74 return E_OGGPLAY_OK;
77 size_t nsChannelReader::io_read(char* aBuffer, size_t aCount)
79 PRUint32 bytes = 0;
80 nsresult rv = mStream.Read(aBuffer, aCount, &bytes);
81 if (!NS_SUCCEEDED(rv)) {
82 return static_cast<size_t>(OGGZ_ERR_SYSTEM);
84 mCurrentPosition += bytes;
85 return bytes;
88 int nsChannelReader::io_seek(long aOffset, int aWhence)
90 nsresult rv = mStream.Seek(aWhence, aOffset);
91 if (NS_SUCCEEDED(rv))
92 return aOffset;
94 return OGGZ_STOP_ERR;
97 long nsChannelReader::io_tell()
99 return mStream.Tell();
102 static OggPlayErrorCode oggplay_channel_reader_initialise(OggPlayReader* aReader, int aBlock)
104 nsChannelReader * me = static_cast<nsChannelReader*>(aReader);
106 if (me == NULL) {
107 return E_OGGPLAY_BAD_READER;
109 return me->initialise(aBlock);
112 static OggPlayErrorCode oggplay_channel_reader_destroy(OggPlayReader* aReader)
114 nsChannelReader* me = static_cast<nsChannelReader*>(aReader);
115 return me->destroy();
118 static size_t oggplay_channel_reader_io_read(void* aReader, void* aBuffer, size_t aCount)
120 nsChannelReader* me = static_cast<nsChannelReader*>(aReader);
121 return me->io_read(static_cast<char*>(aBuffer), aCount);
124 static int oggplay_channel_reader_io_seek(void* aReader, long aOffset, int aWhence)
126 nsChannelReader* me = static_cast<nsChannelReader*>(aReader);
127 return me->io_seek(aOffset, aWhence);
130 static long oggplay_channel_reader_io_tell(void* aReader)
132 nsChannelReader* me = static_cast<nsChannelReader*>(aReader);
133 return me->io_tell();
136 nsresult nsChannelReader::Init(nsMediaDecoder* aDecoder, nsIURI* aURI,
137 nsIChannel* aChannel,
138 nsIStreamListener** aStreamListener)
140 mCurrentPosition = 0;
141 return mStream.Open(aDecoder, aURI, aChannel, aStreamListener);
144 nsChannelReader::~nsChannelReader()
146 MOZ_COUNT_DTOR(nsChannelReader);
149 nsChannelReader::nsChannelReader()
151 MOZ_COUNT_CTOR(nsChannelReader);
152 OggPlayReader* reader = this;
153 reader->initialise = &oggplay_channel_reader_initialise;
154 reader->destroy = &oggplay_channel_reader_destroy;
155 reader->seek = nsnull;
156 reader->io_read = &oggplay_channel_reader_io_read;
157 reader->io_seek = &oggplay_channel_reader_io_seek;
158 reader->io_tell = &oggplay_channel_reader_io_tell;
159 reader->duration = nsnull;
162 nsIPrincipal*
163 nsChannelReader::GetCurrentPrincipal()
165 return mStream.GetCurrentPrincipal();