blob: f764121a0dff2b73910834ac9220e038ae23be69 [file] [log] [blame]
Wei-Ta Chen4b6f4942009-09-01 17:44:49 +08001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
James Dong8e9d67a2012-02-06 23:46:37 -080017#include <media/stagefright/foundation/ADebug.h>
Wei-Ta Chen4b6f4942009-09-01 17:44:49 +080018
19#include "StreamSource.h"
20
21namespace android {
22
23StreamSource::StreamSource(SkStream *stream)
24 : mStream(stream) {
25 CHECK(stream != NULL);
26 mSize = stream->getLength();
27}
28
29StreamSource::~StreamSource() {
30 delete mStream;
31 mStream = NULL;
32}
33
Wei-Ta Chenb3550122009-12-03 23:19:19 +080034status_t StreamSource::initCheck() const {
Wei-Ta Chen4b6f4942009-09-01 17:44:49 +080035 return mStream != NULL ? OK : NO_INIT;
36}
37
James Dongb1262a82010-11-16 14:04:54 -080038ssize_t StreamSource::readAt(off64_t offset, void *data, size_t size) {
Wei-Ta Chen4b6f4942009-09-01 17:44:49 +080039 Mutex::Autolock autoLock(mLock);
40
41 mStream->rewind();
42 mStream->skip(offset);
43 ssize_t result = mStream->read(data, size);
44
45 return result;
46}
47
James Dongb1262a82010-11-16 14:04:54 -080048status_t StreamSource::getSize(off64_t *size) {
Wei-Ta Chen4b6f4942009-09-01 17:44:49 +080049 *size = mSize;
50 return OK;
51}
52
53} // namespace android