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