FileSource.cpp revision 0c89199745bc1bf05b997fc7c342017807676b6f
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/FileSource.h> 18#include <media/stagefright/MediaDebug.h> 19 20namespace android { 21 22FileSource::FileSource(const char *filename) 23 : mFile(fopen(filename, "rb")) { 24} 25 26FileSource::~FileSource() { 27 if (mFile != NULL) { 28 fclose(mFile); 29 mFile = NULL; 30 } 31} 32 33status_t FileSource::InitCheck() const { 34 return mFile != NULL ? OK : NO_INIT; 35} 36 37ssize_t FileSource::read_at(off_t offset, void *data, size_t size) { 38 Mutex::Autolock autoLock(mLock); 39 40 int err = fseeko(mFile, offset, SEEK_SET); 41 CHECK(err != -1); 42 43 ssize_t result = fread(data, 1, size, mFile); 44 45 return result; 46} 47 48} // namespace android 49