1 // Copyright (C) 2021 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "host-common/MediaVideoToolBoxUtils.h"
16 #include "render-utils/MediaNative.h"
17 
18 #define MEDIA_VTB_DEBUG 0
19 
20 #if MEDIA_VTB_DEBUG
21 #define VTB_DPRINT(fmt, ...)                                          \
22     fprintf(stderr, "vtb-utils: %s:%d " fmt "\n", __func__, __LINE__, \
23             ##__VA_ARGS__);
24 #else
25 #define VTB_DPRINT(fmt, ...)
26 #endif
27 
28 extern "C" {
29 #define MEDIA_VTB_COPY_Y_TEXTURE 1
30 #define MEDIA_VTB_COPY_UV_TEXTURE 2
31 
media_vtb_utils_nv12_updater(void * privData,uint32_t type,uint32_t * textures,void * callerData)32 void media_vtb_utils_nv12_updater(void* privData,
33                                   uint32_t type,
34                                   uint32_t* textures,
35                                   void* callerData) {
36     constexpr uint32_t kFRAMEWORK_FORMAT_NV12 = 3;
37     if (type != kFRAMEWORK_FORMAT_NV12) {
38         return;
39     }
40     // get the textures
41     media_vtb_utils_copy_context* myctx =
42             (media_vtb_utils_copy_context*)privData;
43     int ww = myctx->dest_width;
44     int hh = myctx->dest_height;
45     void* iosurface = myctx->iosurface;
46     int yy = 0;
47     int uv = 0;
48 
49     MediaNativeCallerData* cdata = (struct MediaNativeCallerData*)callerData;
50 
51     void* nscontext = cdata->ctx;
52     auto converter = cdata->converter;
53     converter(nscontext, iosurface, textures[0], textures[1]);
54 
55     VTB_DPRINT("done ");
56 }
57 
58 }  // end of extern C
59