void MmRendererPlayerVideoRendererControl::detachDisplay()
{
    m_windowGrabber->stop();

    if (m_surface)
        m_surface->stop();

    if (m_context && m_videoId != -1)
        mmr_output_detach(m_context, m_videoId);

    m_context = 0;
    m_videoId = -1;
}
Ejemplo n.º 2
0
void BbVideoWindowControl::detachDisplay()
{
    if (m_context && m_videoId != -1)
        mmr_output_detach(m_context, m_videoId);

    m_context = 0;
    m_videoId = -1;
    m_metaData.clear();
    m_windowName.clear();
    m_window = 0;
    m_hue = 0;
    m_brightness = 0;
    m_contrast = 0;
    m_saturation = 0;
}
void MmRendererMediaPlayerControl::detach()
{
    if (m_context) {
        if (m_inputAttached) {
            mmr_input_detach(m_context);
            m_inputAttached = false;
        }
        if (m_videoRendererControl)
            m_videoRendererControl->detachDisplay();
        if (m_videoWindowControl)
            m_videoWindowControl->detachDisplay();
        if (m_audioId != -1 && m_context) {
            mmr_output_detach(m_context, m_audioId);
            m_audioId = -1;
        }
    }

    m_loadingTimer.stop();
}
Ejemplo n.º 4
0
void BbMediaPlayerControl::detach()
{
    if (m_context) {
        if (m_inputAttached) {
            mmr_input_detach(m_context);
            m_inputAttached = false;
        }
        if (m_videoControl)
            m_videoControl->detachDisplay();
        if (m_audioId != -1 && m_context) {
            mmr_output_detach(m_context, m_audioId);
            m_audioId = -1;
        }
    }

    if (!m_tempMediaFileName.isEmpty()) {
        QFile::remove(m_tempMediaFileName);
        m_tempMediaFileName.clear();
    }
    m_loadingTimer.stop();
}
Ejemplo n.º 5
0
int main(int argc, char *argv[])
{
    int rc;
    int exit_application = 0;

    // Screen variables
    screen_context_t    screen_context = 0;
    screen_window_t     screen_window = 0;

    int screen_size[2] = {0,0};

    // Renderer variables
    mmr_connection_t*     mmr_connection = 0;
    mmr_context_t*        mmr_context = 0;
    strm_dict_t*          dict = NULL;

    // I/O variables
    int                    video_device_output_id = -1;
    int                    audio_device_output_id = -1;

    bps_initialize();

    /*
     * Create the window used for video output.
     */
    if (screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT) != 0) {
        return EXIT_FAILURE;
    }

    if (screen_create_window(&screen_window, screen_context) != 0) {
        screen_destroy_context(screen_context);
        return EXIT_FAILURE;
    }

    if (screen_create_window_group(screen_window, window_group_name) != 0) {
        return EXIT_FAILURE;
    }

    int format = SCREEN_FORMAT_RGBA8888;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_FORMAT, &format) != 0) {
        return EXIT_FAILURE;
    }

    int usage = SCREEN_USAGE_NATIVE;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_USAGE, &usage) != 0) {
        return EXIT_FAILURE;
    }


    if (screen_create_window_buffers(screen_window, 1) != 0) {
        return EXIT_FAILURE;
    }

    /*
     * Configure mm-renderer.
     */
    mmr_connection = mmr_connect(NULL);
    if (mmr_connection == NULL) {
        return EXIT_FAILURE;
    }

    mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
    if (mmr_context == NULL) {
        return EXIT_FAILURE;
    }

    /*
     * Configure video and audio output.
     */
    video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");
    if (video_device_output_id == -1) {
        return EXIT_FAILURE;
    }

    audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
    if (audio_device_output_id == -1) {
        return EXIT_FAILURE;
    }

    // Get the render buffer
    screen_buffer_t temp_buffer[1];
    if (screen_get_window_property_pv( screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void**)temp_buffer) != 0) {
        return EXIT_FAILURE;
    }

    // Fill the buffer with a solid color (black)
    int fill_attributes[3] = {SCREEN_BLIT_COLOR, 0x0, SCREEN_BLIT_END};
    if (screen_fill(screen_context, temp_buffer[0], fill_attributes) != 0) {
        return EXIT_FAILURE;
    }

    // Make the window visible
    if (screen_get_window_property_iv(screen_window, SCREEN_PROPERTY_SIZE, screen_size) != 0) {
        return EXIT_FAILURE;
    }

    int temp_rectangle[4] = {0, 0, screen_size[0], screen_size[1]};
    if (screen_post_window(screen_window, temp_buffer[0], 1, temp_rectangle, 0) != 0) {
        return EXIT_FAILURE;
    }

    // Prevent the backlight from going off
    int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
    if (screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_IDLE_MODE, &idle_mode) != 0) {
        return EXIT_FAILURE;
    }

    // Build up the path where our bundled resource is.
    char cwd[PATH_MAX];
    char media_file[PATH_MAX];
    getcwd(cwd,PATH_MAX);

    rc = snprintf(media_file, PATH_MAX, "file://%s/app/native/pb_sample.mp4", cwd);
    if ((rc == -1) || (rc >= PATH_MAX)) {
        return EXIT_FAILURE;
    }

    /*
     * Start the playback.
     */
    if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_play(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    /* Do some work to make the aspect ratio correct.
     */
    dict = calculate_rect(screen_size[0], screen_size[1]);
    if (NULL == dict) {
        return EXIT_FAILURE;
    }

    if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) {
        return EXIT_FAILURE;
    }

     /* Note that we allocated memory for the dictionary, but the call to 
      * mmr_output_parameters() deallocates that memory even on failure.
      */  
    dict = NULL;

    screen_request_events(screen_context);
    navigator_request_events(0);

    /*
     * Handle keyboard events and stop playback upon user request.
     */
    for (;;) {
        bps_event_t *event = NULL;
        if (bps_get_event(&event, -1) != BPS_SUCCESS) {
            return EXIT_FAILURE;
        }

        if (event) {

            if (bps_event_get_domain(event) == navigator_get_domain() &&
                bps_event_get_code(event) == NAVIGATOR_EXIT) {

                exit_application = 1;
            }

            if (exit_application) {
                break;
            }
        }
    }

    screen_stop_events(screen_context);

    if (mmr_stop(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
        return EXIT_FAILURE;
    }

    if (mmr_context_destroy(mmr_context) != 0) {
        return EXIT_FAILURE;
    }

    mmr_context = 0;
    video_device_output_id = -1;
    audio_device_output_id = -1;

    mmr_disconnect(mmr_connection);
    mmr_connection = 0;

    bps_shutdown();

    if (screen_destroy_window(screen_window) != 0) {
        return EXIT_FAILURE;
    }

    if (screen_destroy_context(screen_context) != 0) {
        return EXIT_FAILURE;
    }

    screen_context = 0;
    screen_window = 0;

    return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
int main(int argc, char *argv[])
{
    int rc;

    // Renderer variables
    mmr_connection_t*     mmr_connection = 0;
    mmr_context_t*        mmr_context = 0;
    strm_dict_t*          dict = NULL;

    // I/O variables
    int                    video_device_output_id = -1;
    int                    audio_device_output_id = -1;

    // Position of the play and stop button.
    static int ctrl_x = 0;
    static int ctrl_y = 0;

    EGLint surface_width;
    EGLint surface_height;

    srand(time(0));
    app_id = rand();

    // I/O devices
    static char *audio_device_url    = "audio:default";
    static char video_device_url[PATH_MAX];
    rc = snprintf(video_device_url, PATH_MAX, "screen:?winid=videosamplewindowgroup_%d&wingrp=videosamplewindowgroup_%d", app_id, app_id);
    if (rc >= PATH_MAX) {
        fprintf(stderr, "URL too long\n");
    }

    // Name of video context...with a random number appended.
    static char video_context_name[PATH_MAX];
    rc = snprintf(video_context_name, PATH_MAX, "samplevideocontextname_%d", app_id);
    if (rc >= PATH_MAX) {
        fprintf(stderr, "Video context name too long\n");
    }

    // Window group name...with the same random number appended.
    static char window_group_name[PATH_MAX];
    rc = snprintf(window_group_name, PATH_MAX, "videosamplewindowgroup_%d", app_id);
    if (rc >= PATH_MAX) {
        fprintf(stderr, "Video context name too long\n");
    }

    // Video file bundled with our app
    static const char *video_file_relative_path = "app/native/pb_sample.mp4";


    bps_initialize();

    // Create the Screen Context.
    if (screen_create_context(&g_screen_ctx, SCREEN_APPLICATION_CONTEXT) != 0) {
        fprintf(stderr, "screen_create_context failed\n");
        return EXIT_FAILURE;
    }

    // Create the window and initialize EGL for GL_ES_1 rendering
    rc = initialize_egl_window(g_screen_ctx, window_group_name);
    if (rc != EXIT_SUCCESS) {
        fprintf(stderr, "initialize_egl_window failed\n");
        return EXIT_FAILURE;
    }

    // Query width and height of the window surface created by utility code
    eglQuerySurface(g_egl_disp, g_egl_surf, EGL_WIDTH, &surface_width);
    eglQuerySurface(g_egl_disp, g_egl_surf, EGL_HEIGHT, &surface_height);
    EGLint err = eglGetError();
    if (err != EGL_SUCCESS) {
        fprintf(stderr, "Unable to query EGL surface dimensions\n");
        return EXIT_FAILURE;
    }

    // Initialize GL for 2D rendering
    glViewport(0, 0, (int)surface_width, (int) surface_height);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    // Set world coordinates to coincide with screen pixels
    glScalef(1.0f / (float)surface_width, 1.0f / (float)surface_height, 1.0f);

    // We can calculate location and verticies of the controls
    ctrl_x = (float)surface_width  / 2 - ctrl_w / 2;
    ctrl_y = (float)surface_height / 2 - ctrl_h / 2;

    g_triangle_vertices[0] = ctrl_x;
    g_triangle_vertices[1] = ctrl_y;

    g_triangle_vertices[2] = ctrl_x;
    g_triangle_vertices[3] = ctrl_y + ctrl_h;

    g_triangle_vertices[4] = ctrl_x + ctrl_w;
    g_triangle_vertices[5] = ctrl_y + ctrl_h / 2;

    g_square_vertices[0] = ctrl_x;
    g_square_vertices[1] = ctrl_y;
    g_square_vertices[2] = ctrl_x;
    g_square_vertices[3] = ctrl_y + ctrl_h;
    g_square_vertices[4] = ctrl_x + ctrl_w;
    g_square_vertices[5] = ctrl_y + ctrl_h;
    g_square_vertices[6] = ctrl_x + ctrl_w;
    g_square_vertices[7] = ctrl_y;
    g_square_vertices[8] = ctrl_x;
    g_square_vertices[9] = ctrl_y;

    // Configure mm-renderer.
    mmr_connection = mmr_connect(NULL);
    if (mmr_connection == NULL) {
        fprintf(stderr, "mmr_connect failed\n");
        return EXIT_FAILURE;
    }

    mmr_context = mmr_context_create(mmr_connection, video_context_name, 0, S_IRWXU|S_IRWXG|S_IRWXO);
    if (mmr_context == NULL) {
        fprintf(stderr, "mmr_context_create failed\n");
        return EXIT_FAILURE;
    }

    // Configure video and audio output.
    video_device_output_id = mmr_output_attach(mmr_context, video_device_url, "video");
    if (video_device_output_id == -1) {
        fprintf(stderr, "mmr_output_attach(video) failed\n");
        return EXIT_FAILURE;
    }

    audio_device_output_id = mmr_output_attach(mmr_context, audio_device_url, "audio");
    if (audio_device_output_id == -1) {
        fprintf(stderr, "mmr_output_attach(audio) failed\n");
        return EXIT_FAILURE;
    }

    // render 'paused'
    render(true);


    // Build up the path where our bundled resource is.
    char cwd[PATH_MAX];
    char media_file[PATH_MAX];
    getcwd(cwd,PATH_MAX);

    rc = snprintf(media_file, PATH_MAX, "file://%s/%s", cwd, video_file_relative_path);
    if ((rc == -1) || (rc >= PATH_MAX)) {
        fprintf(stderr, "snprintf(media_file) failed\n");
        return EXIT_FAILURE;
    }

    // Attach the input media.
    if (mmr_input_attach(mmr_context, media_file, "track") != 0) {
        fprintf(stderr, "mmr_input_attach(track) failed\n");
        return EXIT_FAILURE;
    }


    int video_speed = 0;

    // Set the speed to 0 to pause the video initially
    if (mmr_speed_set(mmr_context, video_speed) != 0) {
        fprintf(stderr, "mmr_set_speed(0) failed\n");
        return EXIT_FAILURE;
    }

    // Change to the play state, although speed is zero
    if (mmr_play(mmr_context) != 0) {
        fprintf(stderr, "mmr_play failed\n");
        return EXIT_FAILURE;
    }

    /* Do some work to make the aspect ratio correct.
     */
    dict = calculate_rect(surface_width, surface_height);
    if (NULL == dict) {
        fprintf(stderr, "calculate_rect failed\n");
        return EXIT_FAILURE;
    }

    if (mmr_output_parameters(mmr_context, video_device_output_id, dict) != 0) {
        fprintf(stderr, "mmr_output_parameters failed\n");
        return EXIT_FAILURE;
    }

    /* Note that we allocated memory for the dictionary, but the call to 
     * mmr_output_parameters() deallocates that memory even on failure.
     */
    dict = NULL;

    screen_request_events(g_screen_ctx);
    navigator_request_events(0);

    screen_window_t video_window = (screen_window_t)0;
    bool app_window_above = true;
    int screen_val;
    int exit_value = EXIT_SUCCESS;

    // Handle keyboard events and stop playback upon user request.
    for (;;) {
        bps_event_t *event = NULL;
        if (bps_get_event(&event, 0) != BPS_SUCCESS) {
            return EXIT_FAILURE;
        }
        if (event) {
            if (bps_event_get_domain(event) == navigator_get_domain()) {
                if (bps_event_get_code(event) == NAVIGATOR_EXIT) {
                    break;
                } else if(NAVIGATOR_SWIPE_DOWN == bps_event_get_code(event)) {
                    if ((screen_window_t)0 != video_window) {

                        app_window_above = !app_window_above;
                        if (app_window_above) {
                            screen_val = 1;
                        } else {
                            screen_val = -1;
                        }
                        if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_ZORDER, &screen_val) != 0) {
                            fprintf(stderr, "screen_set_window_property(ZORDER) failed\n");
                            exit_value = EXIT_FAILURE;
                            break;
                        }

                        screen_val = 1;
                        if (screen_set_window_property_iv(video_window, SCREEN_PROPERTY_VISIBLE, &screen_val) != 0) {
                            fprintf(stderr, "screen_set_window_property(VISIBLE) failed\n");
                            exit_value = EXIT_FAILURE;
                            break;
                        }

                        rc = screen_flush_context(g_screen_ctx, SCREEN_WAIT_IDLE);
                        if (rc != 0) {
                            fprintf (stderr, "Warning: Failed to flush\n");
                        }
                    }
                }
            } else if (bps_event_get_domain(event) == screen_get_domain()) {
                screen_event_t screen_event = screen_event_get_event(event);
                int event_type;
                screen_get_event_property_iv(screen_event, SCREEN_PROPERTY_TYPE, &event_type);

                if (event_type == SCREEN_EVENT_CREATE && (video_window == (screen_window_t)0)) {
                    char id[256];

                    rc = screen_get_event_property_pv(screen_event, SCREEN_PROPERTY_WINDOW, (void**)&video_window);
                    if (rc != 0) {
                        fprintf(stderr, "screen_get_event_property(WINDOW) failed\n");
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                    fprintf(stderr, "video_window%d\n",(int)video_window);

                    rc = screen_get_window_property_cv(video_window, SCREEN_PROPERTY_ID_STRING, 256, id);
                    if (rc != 0) {
                        fprintf(stderr, "screen_get_window_property(ID) failed\n");
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                    fprintf(stderr, "window ID is %s\n", id);

                    if (strncmp(id, window_group_name, strlen(window_group_name)) != 0) {
                        fprintf(stderr, "window ID mismatch\n");
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                } else if(event_type == SCREEN_EVENT_MTOUCH_TOUCH) {
                    if (video_speed == 0) {
                        video_speed = 1000;
                        render(false);
                    } else {
                        video_speed = 0;
                        render(true);
                    }

                    if (mmr_speed_set(mmr_context, video_speed) != 0) {
                        fprintf(stderr, "mmr_speed_set(%d) failed\n", video_speed);
                        exit_value = EXIT_FAILURE;
                        break;
                    }
                }
            }
        }
    }

    screen_stop_events(g_screen_ctx);

    if (mmr_stop(mmr_context) != 0) {
        fprintf(stderr, "mmr_stop failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, audio_device_output_id) != 0) {
        fprintf(stderr, "mmr_output_detach(audio) failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (mmr_output_detach(mmr_context, video_device_output_id) != 0) {
        fprintf(stderr, "mmr_output_detach(video) failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (mmr_context_destroy(mmr_context) != 0) {
        fprintf(stderr, "mmr_context_destroy failed\n");
        exit_value = EXIT_FAILURE;
    }

    mmr_context = 0;
    video_device_output_id = -1;
    audio_device_output_id = -1;

    mmr_disconnect(mmr_connection);
    mmr_connection = 0;

    bps_shutdown();

    if (screen_destroy_window(g_screen_win) != 0) {
        fprintf(stderr, "screen_destroy_window failed\n");
        exit_value = EXIT_FAILURE;
    }

    if (screen_destroy_context(g_screen_ctx) != 0) {
        fprintf(stderr, "screen_destroy_context failed\n");
        exit_value = EXIT_FAILURE;
    }

    g_screen_ctx = 0;
    g_screen_win = 0;

    return exit_value;
}