blob: 92498429b9e0ec77fea85b108cf84c829b63bb14 [file] [log] [blame]
Andreas Huber20111aa2009-07-14 16:56:47 -07001/*
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#ifndef FILE_SOURCE_H_
18
19#define FILE_SOURCE_H_
20
21#include <stdio.h>
22
Marco Nelissen42057ce2019-09-23 12:15:57 -070023#include <datasource/ClearFileSource.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070024#include <media/stagefright/MediaErrors.h>
25#include <utils/threads.h>
Gloria Wangdcd25ef2010-06-22 13:55:38 -070026#include <drm/DrmManagerClient.h>
Andreas Huber20111aa2009-07-14 16:56:47 -070027
28namespace android {
29
Dongwon Kang1e1bcaa2018-08-01 12:44:46 -070030class FileSource : public ClearFileSource {
Andreas Huber20111aa2009-07-14 16:56:47 -070031public:
32 FileSource(const char *filename);
Glenn Kasten2301acc2014-01-17 10:21:00 -080033 // FileSource takes ownership and will close the fd
Andreas Huber03475f52009-11-16 15:34:01 -080034 FileSource(int fd, int64_t offset, int64_t length);
Andreas Huber34769bc2009-10-23 10:22:30 -070035
James Dongc7fc37a2010-11-16 14:04:54 -080036 virtual ssize_t readAt(off64_t offset, void *data, size_t size);
Andreas Huber34769bc2009-10-23 10:22:30 -070037
James Dong9d2f3862012-01-10 08:24:37 -080038 virtual sp<DecryptHandle> DrmInitialization(const char *mime);
Gloria Wangdcd25ef2010-06-22 13:55:38 -070039
Andy Hungd49dbd62016-07-07 14:20:35 -070040 static bool requiresDrm(int fd, int64_t offset, int64_t length, const char *mime);
41
Andreas Huber34769bc2009-10-23 10:22:30 -070042protected:
Andreas Huber20111aa2009-07-14 16:56:47 -070043 virtual ~FileSource();
44
Andreas Huber20111aa2009-07-14 16:56:47 -070045private:
Gloria Wangdcd25ef2010-06-22 13:55:38 -070046 /*for DRM*/
Gloria Wangb5ce3612011-02-24 16:40:57 -080047 sp<DecryptHandle> mDecryptHandle;
Gloria Wangdcd25ef2010-06-22 13:55:38 -070048 DrmManagerClient *mDrmManagerClient;
49 int64_t mDrmBufOffset;
Patrik Lindgrend066bc82014-12-22 09:06:21 +010050 ssize_t mDrmBufSize;
Gloria Wangdcd25ef2010-06-22 13:55:38 -070051 unsigned char *mDrmBuf;
52
Dongwon Kang1e1bcaa2018-08-01 12:44:46 -070053 ssize_t readAtDRM_l(off64_t offset, void *data, size_t size);
Gloria Wangdcd25ef2010-06-22 13:55:38 -070054
Andreas Huber20111aa2009-07-14 16:56:47 -070055 FileSource(const FileSource &);
56 FileSource &operator=(const FileSource &);
57};
58
59} // namespace android
60
61#endif // FILE_SOURCE_H_
62