• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018, 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 A_MEDIA_DATA_SOURCE_CALLBACKS_H
18 
19 #define A_MEDIA_DATA_SOURCE_CALLBACKS_H
20 
21 #include <media/DataSource.h>
22 #include <media/NdkMediaDataSource.h>
23 #include <media/NdkMediaError.h>
24 #include <sys/types.h>
25 
26 namespace android {
27 
28 ssize_t DataSource_getSize(void *userdata);
29 
30 ssize_t DataSource_readAt(void *userdata, off64_t offset, void * buf, size_t size);
31 
32 void DataSource_close(void *userdata);
33 
34 ssize_t DataSource_getAvailableSize(void *userdata, off64_t offset);
35 
convertDataSourceToAMediaDataSource(const sp<DataSource> & source)36 static inline AMediaDataSource* convertDataSourceToAMediaDataSource(const sp<DataSource> &source) {
37     if (source == NULL) {
38         return NULL;
39     }
40     AMediaDataSource *mSource = AMediaDataSource_new();
41     AMediaDataSource_setUserdata(mSource, source.get());
42     AMediaDataSource_setReadAt(mSource, DataSource_readAt);
43     AMediaDataSource_setGetSize(mSource, DataSource_getSize);
44     AMediaDataSource_setClose(mSource, DataSource_close);
45     AMediaDataSource_setGetAvailableSize(mSource, DataSource_getAvailableSize);
46     return mSource;
47 }
48 
49 }  // namespace android
50 
51 #endif  // A_MEDIA_DATA_SOURCE_CALLBACKS_H
52