StreamSource.cpp revision 4b6f4942fcef3300b407d9a07a680c07b162333f
1/*
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
17#include <media/stagefright/MediaDebug.h>
18
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
34status_t StreamSource::InitCheck() const {
35    return mStream != NULL ? OK : NO_INIT;
36}
37
38ssize_t StreamSource::read_at(off_t offset, void *data, size_t size) {
39    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
48status_t StreamSource::getSize(off_t *size) {
49      *size = mSize;
50      return OK;
51}
52
53}  // namespace android
54