void producer_post_frames()

in sample/video_frame_producer_sample.c [195:249]


void producer_post_frames()
{
    if (log_producer_env_init(LOG_GLOBAL_ALL) != LOG_PRODUCER_OK) {
        exit(1);
    }

    log_producer * producer = create_log_producer_wrapper(on_log_send_done);
    if (producer == NULL)
    {
        printf("create producer by config fail \n");
        exit(1);
    }

    log_producer_client * client = get_log_producer_client(producer, NULL);
    if (client == NULL)
    {
        printf("create producer client by config fail \n");
        exit(1);
    }

    srand(time(NULL));

    int i = 0;
    for (; i < 100; ++i)
    {
        video_frame frame;
        // 每10帧有一个为关键帧
        frame.frame_flag = i % 10 == 0 ? FRAME_FLAG_KEY_FRAME : FRAME_FLAG_NONE;

        // mock 帧数据
        uint32_t data_size = 960*720;
        uint8_t * frame_data = (uint8_t *)malloc(data_size);
        memset(frame_data, i % 256, data_size);
        frame.frame_data_size = data_size;
        frame.frame_data = frame_data;

        frame.duration = rand() % 500;
        frame.decoding_timestamp = time(NULL);
        frame.presentation_timestamp = time(NULL);
        char extra_info[32];
        sprintf(extra_info, "extra_%d", i);
        frame.extra_info = (uint8_t *)extra_info;
        frame.extra_info_size = strlen(extra_info);

        // 发送帧数据
        post_frame(client, &frame);

        free(frame_data);

        usleep(30000);
    }

    destroy_log_producer(producer);
    log_producer_env_destroy();
}