/****************************************************************************
 *NAME    
 *    avrcpHandleGetPlayStatusResponse  
 *
 *DESCRIPTION
 *  Handle Get Play Status response received from the TG.
 *
 *PARAMETERS
 * avrcp            - AVRCP instance
 * status           - Application status
 * transaction      - Transaction ID
 * ptr              - Pointer to response data packet.
 * packet_size      - size of data packet.
 ****************************************************************************/
void avrcpHandleGetPlayStatusResponse(AVRCP             *avrcp, 
                                      avrcp_status_code status,
                                      uint16            transaction, 
                                      const  uint8      *ptr, 
                                      uint16            packet_size)
{
    uint32 song_length = 0, song_elapsed = 0;
    uint8 play_status =0;

    /* packet should be 9 bytes*/
    if((packet_size >= AVRCP_GET_PLAY_STATUS_SIZE) &&
       (status < AVRCP_ERROR_STATUS_BASE ))
    {
        /* Song length in 0-3 bytes */
        song_length = convertUint8ValuesToUint32(&ptr[0]);

        /* song elapsed in 4-7 bytes */
        song_elapsed = convertUint8ValuesToUint32(&ptr[4]);

        /* copy play status in the 8th byte*/
        play_status = ptr[8];
    } 

    avrcpSendGetPlayStatusCfm(avrcp, status,
                              song_length, song_elapsed, play_status, 
                              transaction);
}
/****************************************************************************
*NAME    
*    AvrcpGetPlayStatus    
*
*DESCRIPTION
*  API function to request GetPlayStatus
*    
*PARAMETERS
*   avrcp            - Task
*
*RETURN
*  AVRCP_GET_PLAY_STATUS_CFM 
*****************************************************************************/
void AvrcpGetPlayStatus(AVRCP *avrcp)
{
    avrcp_status_code status = avrcpMetadataStatusCommand(avrcp, 
                                                AVRCP_GET_PLAY_STATUS_PDU_ID,
                                                avrcp_get_play_status, 
                                                0, 0, 0, 0);

    if (status != avrcp_success)
    {
        avrcpSendGetPlayStatusCfm(avrcp, status, 0, 0, 0, 0);
    }
}
bool avrcpHandleGetPlayStatusResponse(AVRCP *avrcp, uint16 transaction, const uint8 *ptr, Source source, uint16 packet_size)
{
	uint32 song_length = 0, song_elapsed = 0;

	/* Only process the response if it is expected. */
	if ((avrcp->pending == avrcp_get_play_status) || (avrcp->continuation_pdu == AVRCP_GET_PLAY_STATUS_PDU_ID))
	{
		song_length = convertUint8ValuesToUint32(&ptr[13]);
		song_elapsed = convertUint8ValuesToUint32(&ptr[17]);
		avrcpSendGetPlayStatusCfm(avrcp, convertResponseToStatus(ptr[3]), song_length, song_elapsed, ptr[21], transaction, source, packet_size);
	}
	else
		return FALSE;

	return TRUE;
}
void avrcpHandleGetPlayStatusResponse(AVRCP             *avrcp, 
                                      avrcp_status_code status,
                                      uint16            transaction, 
                                      const  uint8      *ptr, 
                                      uint16            packet_size)
{
    uint32 song_length = 0, song_elapsed = 0;
    uint8 play_status =0;

    if(status == avrcp_rejected)
    {
        /* next data is error status code */
        status = ptr[0] + avrcp_rejected_invalid_pdu;
    }

    /* packet should be greater than 9 bytes */
    if(packet_size < AVRCP_GET_PLAY_STATUS_SIZE)
    {
        AVRCP_INFO(("avrcpHandleGetPlayStatusResponse: Invalid Length\n",
                    packet_length)); 
    }
    else
    {
        /* Song length in 0-3 bytes */
        song_length = convertUint8ValuesToUint32(&ptr[0]);

        /* song elapsed in 4-7 bytes */
        song_elapsed = convertUint8ValuesToUint32(&ptr[4]);

        /* copy play status in the 8th byte*/
        play_status = ptr[8];
    } 

    avrcpSendGetPlayStatusCfm(avrcp, status,
                              song_length, song_elapsed, play_status, 
                              transaction);
}