📄 receiver.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 receiver.c
* \brief Receiver.
*
* \verbatim
*
* $Log$
*
* \endverbatim
*/
#include <cfg/os.h>
#include <cfg/clock.h>
#include <dev/board.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <sys/version.h>
#include <sys/confnet.h>
#include <sys/atom.h>
#include <sys/heap.h>
#include <sys/thread.h>
#include <sys/timer.h>
#include <sys/event.h>
#include <sys/socket.h>
#include <hxmp3/mp3dec.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <net/route.h>
#include <pro/dhcp.h>
#include "tlv320dac.h"
#include "config.h"
#include "receiver.h"
#include "shoutcast.h"
/*!
* \brief Create stream receiver instance with the specified plug-in.
*
* \param plugin Pointer to a receiver plug-in.
*
* \return Pointer to the receiver info structure or NULL, if the creation
* failed.
*/
RECEIVERINFO * ReceiverCreate(RECEIVERPLUGIN *plugin)
{
RECEIVERINFO *rip;
/* Allocate and initialize the receiver info structure. */
if ((rip = malloc(sizeof(RECEIVERINFO))) != NULL) {
memset(rip, 0, sizeof(RECEIVERINFO));
rip->ri_rpp = plugin;
/* Associate a new player plug-in instance. */
if ((*plugin->rp_create) (rip)) {
free(rip);
rip = NULL;
}
}
return rip;
}
/*!
* \brief Change receiver plug-in status.
*
* \param rip Points to the receiver information structure.
* \param sst Command status to set, either RSTAT_STOP or \ref RSTAT_START.
* \param xst Expected final status, \ref RSTAT_IDLE or \ref RSTAT_RUNNING.
*
* \return 0 on success, -1 otherwise.
*/
static int ReceiverPlugInControl(RECEIVERINFO *rip, u_int sst, u_int xst)
{
int retries = 40;
while (rip->ri_status != xst) {
rip->ri_status = sst;
NutEventPost(&rip->ri_cmdevt);
if (retries-- <= 0) {
printf("No receiver control\n");
return -1;
}
NutEventWait(&rip->ri_stsevt, 500);
}
return 0;
}
/*!
* \brief Retrieve the current receiver status.
*
* \param rip Pointer to the receiver information structure.
*
* \return Receiver status.
*/
u_int ReceiverStatus(RECEIVERINFO *rip)
{
return rip->ri_status;
}
/*!
* \brief Stop receiver.
*
* \param rip Receiver to stop.
*
* \return 0 on success, -1 otherwise.
*/
int ReceiverStop(RECEIVERINFO *rip)
{
printf("[RSTOP]");
return ReceiverPlugInControl(rip, RSTAT_STOP, RSTAT_IDLE);
}
/*!
* \brief Start receiving a specified station.
*
* \param rip Receiver to start.
* \param sip Station to receive.
*
* \return 0 on success, -1 otherwise.
*/
int ReceiverStart(RECEIVERINFO *rip, STATIONINFO *sip)
{
/* Make sure that the receiver is not running. */
if (ReceiverStop(rip)) {
return -1;
}
printf("[RSTART]");
rip->ri_sip = sip;
rip->ri_wpos = 0;
rip->ri_rpos = 0;
rip->ri_avail = 0;
if ((*rip->ri_rpp->rp_setup)(rip)) {
return -1;
}
return ReceiverPlugInControl(rip, RSTAT_START, RSTAT_RUNNING);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -