| /** |
| * Copyright (C) 2020 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #include <media/stagefright/MediaExtractor.h> |
| #include <media/MediaDefs.h> |
| |
| #include "../includes/common.h" |
| #include "../includes/memutils.h" |
| |
| char enable_selective_overload = ENABLE_NONE; |
| |
| using namespace android; |
| |
| class XMFDataSource : public DataSource { |
| public: |
| int mFdData; |
| int mFdInfo; |
| XMFDataSource(int fdData, int fdInfo) { |
| mFdData = fdData; |
| mFdInfo = fdInfo; |
| } |
| |
| ~XMFDataSource() = default; |
| |
| virtual ssize_t readAt(off64_t offset __attribute__((unused)), void *data, size_t size) { |
| uint32_t infoOffset, infoSize; |
| read(mFdInfo, &infoSize, sizeof(int32_t)); |
| read(mFdInfo, &infoOffset, sizeof(int32_t)); |
| lseek(mFdData, infoOffset, SEEK_SET); |
| read(mFdData, data, infoSize); |
| return size; |
| } |
| |
| virtual status_t getSize(off64_t *size) { |
| *size = 0x10000; |
| return 0; |
| } |
| virtual status_t initCheck() const { return 0; } |
| }; |
| |
| void close_resources(int fdData, int fdInfo) { |
| if (fdData >= 0) { |
| ::close(fdData); |
| } |
| if (fdInfo >= 0) { |
| ::close(fdInfo); |
| } |
| } |
| |
| int main(int argc, char **argv) { |
| if (argc < 3) { |
| return EXIT_FAILURE; |
| } |
| enable_selective_overload = ENABLE_ALL; |
| |
| int fdData = open(argv[1], O_RDONLY); |
| if (fdData < 0) { |
| return EXIT_FAILURE; |
| } |
| int fdInfo = open(argv[2], O_RDONLY); |
| if (fdInfo < 0) { |
| close_resources(fdData, fdInfo); |
| return EXIT_FAILURE; |
| } |
| |
| sp<DataSource> xmfSource = (sp<DataSource>)new XMFDataSource(fdData, fdInfo); |
| if (xmfSource == nullptr) { |
| close_resources(fdData, fdInfo); |
| return EXIT_FAILURE; |
| } |
| |
| sp<IMediaExtractor> extractor = |
| MediaExtractor::CreateFromService(xmfSource, MEDIA_MIMETYPE_AUDIO_MIDI); |
| |
| close_resources(fdData, fdInfo); |
| enable_selective_overload = ENABLE_NONE; |
| return EXIT_SUCCESS; |
| } |