I am porting my Android AOSP-based distribution from Android K to Android N. It includes a modified version of the Media Player that decodes DVD subtitles. The architecture of the Media Player evolved a lot between those 2 versions. In particular, it is now split into 3 processes (see https://source.android.com/devices/media/framework-hardening).
I am thus trying to use Shared Memory to make the MediaCodecService send decoded bitmap subtitles to the MediaServer. I modified the contents of the structure that was previously created by MediaCodecService and added a subtitle_fd attribute, file descriptor to the decoded bitmap subtitle. When a message is received by the MediaServer's Nuplayer for rendering, the code tries to map the aforementioned file descriptor.
Unfortunately, the result of the call to ::mmap is always MAP_FAILED.
Do you have an idea of what I missed ?
Code of the MediaCodecService part
AVSubtitleRect *rect = sub->rects[0]; size_t len = sizeof(*rect); int fd = ashmem_create_region("subtitle rect", len); ashmem_set_prot_region(fd, PROT_READ | PROT_WRITE); void* ptr = ::mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED) { ALOGI("%s[%d] dvb ptr == MAP_FAILED", __FUNCTION__, __LINE__); } else { ALOGI("Success creating FD with value %d", fd); } memcpy(ptr, rect, len); sub->subtitle_fd = fd; sub->subtitle_size = len;
Code of the MediaServer part
int fd = mSubtitle->subtitle_fd; size_t len = mSubtitle->subtitle_size; ALOGI("Trying to map shared memory with FD = %d", fd); void* ptr = ::mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (ptr == MAP_FAILED) { ALOGI("Subtitle mmap ptr==MAP_FAILED %s", strerror(errno)); } else { ALOGI("Subtitle get ptr %p", ptr); } AVSubtitleRect *rect = (AVSubtitleRect *)ptr;
Thank you so much !