• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/foundation/ADebug.h>
18 
19 #include "StreamSource.h"
20 
21 namespace android {
22 
StreamSource(SkStream * stream)23 StreamSource::StreamSource(SkStream *stream)
24         : mStream(stream) {
25     CHECK(stream != NULL);
26     mSize = stream->getLength();
27 }
28 
~StreamSource()29 StreamSource::~StreamSource() {
30     delete mStream;
31     mStream = NULL;
32 }
33 
initCheck() const34 status_t StreamSource::initCheck() const {
35     return mStream != NULL ? OK : NO_INIT;
36 }
37 
readAt(off64_t offset,void * data,size_t size)38 ssize_t StreamSource::readAt(off64_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 
getSize(off64_t * size)48 status_t StreamSource::getSize(off64_t *size) {
49       *size = mSize;
50       return OK;
51 }
52 
53 }  // namespace android
54