コード例 #1
0
/******************************************************************************
* Function: jpeg_queue_reset
* Description: Resets the queue object
* Input parameters:
*  queue              - The queue object to be reset.
* Return values:
*     JPEGERR_SUCCESS
*     JPEGERR_ENULLPTR
* Notes: none
*****************************************************************************/
int  jpeg_queue_reset(jpeg_queue_t  queue)
{
    jpeg_q_t *p_q = (jpeg_q_t *)queue;
    int rc = JPEGERR_SUCCESS;

    if (!p_q)
    {
        JPEG_DBG_ERROR("jpeg_queue_reset: failed with empty queue pointer\n");
        return JPEGERR_ENULLPTR;
    }

    // Abort previous queue
    rc = jpeg_queue_abort(&queue);
    if (JPEG_FAILED(rc))
    {
        JPEG_DBG_ERROR("jpeg_queue_reset: jpeg_queue_abort failed \n");
        return rc;
    }

    os_mutex_lock(&(p_q->mutex));

    // Initialize queue head, tail and counts all to zero
    p_q->queue_head = 0;
    p_q->queue_tail = 0;
    p_q->queue_cnt = 0;
    (void)STD_MEMSET(&(p_q->queue_pool), 0, sizeof(jpeg_queue_pool_t));

    p_q->state = QUEUE_STATE_IDLE;
    os_mutex_unlock(&(p_q->mutex));
    return JPEGERR_SUCCESS;
}
コード例 #2
0
ファイル: hw_encode.c プロジェクト: dancingalone/sharescreen
OS_THREAD_FUNC_RET_T OS_THREAD_FUNC_MODIFIER hw_engine_encode (OS_THREAD_FUNC_ARG_T arg)
{
//	char *output_filename;
	thread_ctrl_blk_t *p_thread_arg = (thread_ctrl_blk_t *) arg;
	int rc, i;
	jpege_obj_t encoder;
	jpege_src_t source;
	jpege_dst_t dest;
	jpege_cfg_t config;
	jpege_img_data_t img_info;	//tn_img_info;
	jpeg_buffer_t main_luma_buf, main_chroma_buf;
	jpeg_buffer_t tn_luma_buf, tn_chroma_buf;
	encoder_args_t *p_args = p_thread_arg->p_args;
	uint8_t use_pmem = false;
	jpeg_buffer_t buffers[2];
	// Append the output file name with a number to avoid multiple writing to the same file
#if 0
	if (p_thread_arg->tid)
	{
		// Look for the last occurence of '/' and then last occurence of '.'
		char *s = strrchr (p_args->output_file, '/');
		if (s)
		{
			s = strrchr (s, '.');
		}
		else
		{
			s = strrchr (p_args->output_file, '.');
		}
		output_filename =
			(char *) malloc (5 + strlen (p_args->output_file));
		sLOG_D (output_filename, "%s", p_args->output_file);
		if (s)
		{
			sLOG_D (output_filename +
				(s - p_args->output_file), "_%.2d%s",
				p_thread_arg->tid, s);
		}
		else
		{
			sLOG_D (output_filename, "%s_%.2d",
				output_filename, p_thread_arg->tid);
		}
	}
#endif
	// Determine whether pmem should be used (useful for pc environment testing where
	// pmem is not available)
	use_pmem = p_args->use_pmem;
	if ((jpege_preference_t) p_args->preference == JPEG_ENCODER_PREF_SOFTWARE_PREFERRED
	    || (jpege_preference_t) p_args->preference == JPEG_ENCODER_PREF_SOFTWARE_ONLY)
	{
		use_pmem = false;
	}

	// Initialize source buffers
	if (jpeg_buffer_init (&main_luma_buf) ||
	    jpeg_buffer_init (&main_chroma_buf) ||
	    jpeg_buffer_init (&tn_luma_buf) ||
	    jpeg_buffer_init (&tn_chroma_buf))
	{
		return OS_THREAD_FUNC_RET_FAILED;
	}

	// Open input file(s) and read the contents
	if (p_args->main.format == YCBCRLP_H2V2
	    || p_args->main.format == YCRCBLP_H2V2)
	{
		if (read_bytes_from_buffer (p_args->main.width,
					    p_args->main.height,
					    &main_luma_buf,
					    &main_chroma_buf, use_pmem,
					    p_args, false))
			return OS_THREAD_FUNC_RET_FAILED;
	}
#if 0
	else if ((p_args->main.format >= JPEG_BITSTREAM_H2V2) &&
		 (p_args->main.format < JPEG_COLOR_FORMAT_MAX))
	{
		if (read_bs_from_file
		    (p_args->main.file_name, p_args->main.width,
		     p_args->main.height, &main_luma_buf, use_pmem))
			return OS_THREAD_FUNC_RET_FAILED;
	}
#endif
	else
	{
		LOG_D ("hw_engine_encode: main inage color format not supported\n");
		return OS_THREAD_FUNC_RET_FAILED;
	}

#if 0
	if (p_args->encode_thumbnail)
	{
		if (p_args->thumbnail.format <= YCBCRLP_H1V1)
		{
			if (read_bytes_from_buffer
			    (p_args->thumbnail.width,
			     p_args->thumbnail.height, &tn_luma_buf,
			     &tn_chroma_buf, use_pmem, p_args, true))
				return OS_THREAD_FUNC_RET_FAILED;
		}
		else if ((p_args->thumbnail.format >= JPEG_BITSTREAM_H2V2)
			 && (p_args->main.format < JPEG_COLOR_FORMAT_MAX))
		{
			if (read_bs_from_file
			    (p_args->thumbnail.file_name,
			     p_args->thumbnail.width,
			     p_args->thumbnail.height, &tn_luma_buf,
			     use_pmem))
				return OS_THREAD_FUNC_RET_FAILED;
		}
		else
		{
			LOG_D ("hw_engine_encode: thumbnail color format not supported\n");
			return OS_THREAD_FUNC_RET_FAILED;
		}
	}
#endif
	// Initialize encoder
	rc = jpege_init (&encoder, &encoder_event_handler,(void *) p_thread_arg);
	if (JPEG_FAILED (rc))
	{
		LOG_D ("hw_engine_encode: jpege_init failed\n");
		return OS_THREAD_FUNC_RET_FAILED;
	}
	p_thread_arg->encoder = encoder;

	// Set source information (main)
	img_info.color_format = p_args->main.format;
	img_info.width = p_args->main.width;
	img_info.height = p_args->main.height;
	img_info.fragment_cnt = 1;
	img_info.p_fragments[0].width = p_args->main.width;
	img_info.p_fragments[0].height = p_args->main.height;
//    	if (img_info.color_format <= YCBCRLP_H1V1)
	{
		img_info.p_fragments[0].color.yuv.luma_buf = main_luma_buf;
		img_info.p_fragments[0].color.yuv.chroma_buf =
			main_chroma_buf;
	}
#if 0
	else if ((img_info.color_format >= JPEG_BITSTREAM_H2V2) &&
コード例 #3
0
/******************************************************************************
* Function: jpeg_queue_dequeue
* Description: Dequeue a entry from the queue.  It returns the double pointer
*              to the entry to be denqueued from the head of queue,
*              and accepts the number of time in mini-seconds that it conditional  .
*              waits if the queue if empty.
* Input parameters:
*   queue              - The queue object.
*   pp_dequeue_buffer  - The double pointer to dequeued entry.
*   ms                 - The time out in minisecond
* Return values:
*     JPEGERR_SUCCESS
*     JPEGERR_EFAILED
*     JPEGERR_ENULLPTR
*     JPEGERR_ETIMEDOUT
* Notes: none
*****************************************************************************/
int jpeg_queue_dequeue(
    jpeg_queue_t   queue,
    void           **pp_dequeue_entry,
    uint32_t       time_out_ms)
{
    uint32_t   q_index;
    jpeg_q_t   *p_q;
    int        rc;

    // Input parameter validation
    if (!pp_dequeue_entry)
    {
        JPEG_DBG_ERROR("jpeg_queue_dequeue: failed with input parameter check\n");
        return JPEGERR_EBADPARM;
    }
    p_q = (jpeg_q_t *)queue;
    if (!p_q)
    {
        JPEG_DBG_ERROR("jpeg_queue_dequeue: failed with empty queue pointer\n");
        return JPEGERR_ENULLPTR;
    }

    os_mutex_lock(&(p_q->mutex));

    if (p_q->state == QUEUE_STATE_ABORTED)
    {
        os_mutex_unlock(&(p_q->mutex));
        JPEG_DBG_ERROR("jpeg_queue_dequeue: Aborted \n");
        return JPEGERR_EFAILED;
    }

    // Check if queue is empty:
    // queue_cnt is current number of entries in queue.
    while (p_q->queue_cnt <= 0 && QUEUE_STATE_ABORT != p_q->state)
    {
        p_q->state = QUEUE_STATE_TIMEWAIT;
        // fails after conditional waiting time_out_ms in milli-seconds
        rc = os_cond_timedwait(&(p_q->get_cond), &(p_q->mutex), time_out_ms);
        if (JPEG_FAILED(rc))
        {
            JPEG_DBG_ERROR("jpeg_queue_dequeue: failed with empty queue\n");
            if (QUEUE_STATE_ABORT == p_q->state)
            {
                p_q->state = QUEUE_STATE_ABORTED;
                os_cond_signal(&(p_q->abort_cond));
            }
            p_q->state = QUEUE_STATE_IDLE;
            os_mutex_unlock(&(p_q->mutex));
            return rc;
        }
    }

    if (QUEUE_STATE_ABORT == p_q->state)
    {
        p_q->state = QUEUE_STATE_IDLE;
        // signal abort cond
        os_cond_signal(&(p_q->abort_cond));
        os_mutex_unlock(&(p_q->mutex));
        JPEG_DBG_ERROR("jpeg_queue_dequeue: failed with abort\n");
        return JPEGERR_EFAILED;
    }

    // Dequeue an entry from queue
    q_index = p_q->queue_head;

    // Dequeue the entry from the head of queue
    *pp_dequeue_entry = p_q->queue_pool[q_index].p_data;

    // Update the head of queue and entries number
    p_q->queue_head = QUEUE_MOD(p_q->queue_head + 1);
    p_q->queue_cnt  -= 1;
    p_q->state = QUEUE_STATE_IDLE;

    os_mutex_unlock(&(p_q->mutex));
    return JPEGERR_SUCCESS;
}