static void stopBackground(bool bReleaseData) { s_playStatus = STOPPED; if (s_mmrContext) mmr_stop(s_mmrContext); if (bReleaseData) { if (s_mmrContext) { mmr_input_detach(s_mmrContext); mmr_context_destroy(s_mmrContext); } if (s_mmrConnection) mmr_disconnect(s_mmrConnection); if (s_repeatDictionary) strm_dict_destroy(s_repeatDictionary); if (s_volumeDictionary) strm_dict_destroy(s_volumeDictionary); s_mmrContext = 0; s_mmrConnection = 0; s_repeatDictionary = 0; s_volumeDictionary = 0; s_hasMMRError = false; s_currentBackgroundStr = ""; s_isBackgroundInitialized = false; } }
/* * we know the video has a resolution of 640x480 so it has an aspect ratio of * of approximately 1.33. Based on these facts, we can show the video as large * as possible without changing the aspect ratio. */ strm_dict_t* calculate_rect(int width, int height) { const int image_width = 640; const int image_height = 480; const float image_aspect = (float)image_width / (float)image_height; const float aspect_tolerance = 0.1; char buffer[16]; strm_dict_t *dict = strm_dict_new(); if (NULL == dict) { return NULL; } //fullscreen is the default. dict = strm_dict_set(dict, "video_dest_x", "0"); if (NULL == dict) goto fail; dict = strm_dict_set(dict, "video_dest_y", "0"); if (NULL == dict) goto fail; dict = strm_dict_set(dict, "video_dest_w", itoa(width, buffer, 10)); if (NULL == dict) goto fail; dict = strm_dict_set(dict, "video_dest_h", itoa(height, buffer, 10)); if (NULL == dict) goto fail; float screen_aspect = (float)width/(float)height; if (fabs(screen_aspect - image_aspect) < aspect_tolerance) { //if the screen is at almost the same aspect as the video, just //do full screen. Nothing to do here. Fall through and return //full screen. } else if (screen_aspect < image_aspect) { /* The screen is too tall. We need to centre top to bottom, set the * width the same as the screen's while maintaining the same aspect * ratio. */ dict = strm_dict_set(dict, "video_dest_y", itoa((height - image_height) / 2, buffer, 10)); if (NULL == dict) goto fail; height = width / image_aspect; dict = strm_dict_set(dict, "video_dest_h", itoa(height, buffer, 10)); if (NULL == dict) goto fail; } else { /* The screen is too wide. We need to centre left to right, set the * height the same as the screen's while maintaining the same aspect * ratio. */ dict = strm_dict_set(dict, "video_dest_x", itoa((width - image_width) / 2, buffer, 10)); if (NULL == dict) goto fail; width = height * image_aspect; dict = strm_dict_set(dict, "video_dest_w", itoa(width, buffer, 10)); if (NULL == dict) goto fail; } return dict; fail: strm_dict_destroy(dict); return NULL; }