📄 player.c
字号:
/*!
* Copyright (C) 2006-2007 by egnite Software GmbH. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
* SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* For additional information see http://www.ethernut.de/
*/
/*!
* \file player.c
* \brief Player.
*
* \verbatim
*
* $Log$
*
* \endverbatim
*/
#include <cfg/os.h>
#include <cfg/clock.h>
#include <dev/board.h>
#include <sys/timer.h>
#include <sys/event.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "tlv320dac.h"
#include "receiver.h"
#include "mp3player.h"
/*!
* \brief Create a player instance.
*
* \param plugin Pointer to a player plug-in.
*
* \return On success, the pointer to a \ref PLAYERINFO structure is returned.
* A NULL pointer indicates an error.
*/
PLAYERINFO * PlayerCreate(PLAYERPLUGIN *plugin)
{
PLAYERINFO *pip;
/* Allocate and initialize the player info structure. */
if ((pip = malloc(sizeof(PLAYERINFO))) != NULL) {
memset(pip, 0, sizeof(PLAYERINFO));
/* Associate a new player plug-in instance. */
if ((*plugin->pp_create) (pip)) {
free(pip);
pip = NULL;
}
}
return pip;
}
/*!
* \brief Set player to a specified state.
*
* \param pip Pointer to a player info structure, obtained by a
* previous call to PlayerCreate().
* \param sst Status to set, typically PSTAT_START or PSTAT_STOP.
* \param xst Status to wait for, like PSTAT_IDLE or PSTAT_RUNNING.
*
* \return 0 on success, -1 otherwise.
*/
static int PlayerPlugInControl(PLAYERINFO *pip, u_int sst, u_int xst)
{
int retries = 10;
/* Loop until we got the status or give up on too many retires. */
while (pip->pi_status != xst) {
pip->pi_status = sst;
NutEventPost(&pip->pi_cmdevt);
if (NutEventWait(&pip->pi_stsevt, 500)) {
if (retries-- <= 0) {
printf("No player control\n");
return -1;
}
}
}
return 0;
}
/*!
* \brief Retrieve the current player status.
*
* \param pip Pointer to a player info structure, obtained by a
* previous call to PlayerCreate().
*
* \return Player status.
*/
u_int PlayerStatus(PLAYERINFO *pip)
{
return pip->pi_status;
}
/*!
* \brief Stop player.
*
* \param pip Player to stop. Pointer to a player info structure,
* obtained by a previous call to PlayerCreate().
*
* \return 0 on success, -1 otherwise.
*/
int PlayerStop(PLAYERINFO *pip)
{
printf("[PSTOP]");
return PlayerPlugInControl(pip, PSTAT_STOP, PSTAT_IDLE);
}
/*!
* \brief Start playing a specified receiver.
*
* \param pip Player to start. Pointer to a player info structure,
* obtained by a previous call to PlayerCreate().
* \param rip Receiver to play.
*
* \return 0 on success, -1 otherwise.
*/
int PlayerStart(PLAYERINFO *pip, RECEIVERINFO *rip)
{
if (PlayerStop(pip)) {
return -1;
}
printf("[PSTART]");
pip->pi_rcvr = rip;
return PlayerPlugInControl(pip, PSTAT_START, PSTAT_RUNNING);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -