void Decoder::init_decoder(const int in_width, const int in_height,
		const int in_pix_fmt, const int codec_ID)
{
	/* Declarations */
	AVCodec *codec;

	/* Find the decoder */
	codec = find_decoder(codec_ID);
	if (!codec)
		throw std::runtime_error("Could not find codec.");

	/* Allocate codec context */
	codec_context_ = avcodec_alloc_context3(codec);
	if (!codec_context_)
		throw std::runtime_error("Could not allocate codec context.");

	/* Set codec configuration */
	codec_context_->pix_fmt = (enum AVPixelFormat) in_pix_fmt;
	codec_context_->coded_width = in_width;
	codec_context_->coded_height = in_height;

	/* Open the codec context */
	if (codec_open(codec_context_, codec, NULL) < 0)
		throw std::runtime_error("Could not open codec context.");

	/* Allocate Decoder AVFrame */
	frame_in_ = boost::make_shared<Frame>(in_width, in_height, in_pix_fmt);

	has_keyframe_ = false;
	previous_packet_ = 0;
}
Exemple #2
0
/*
======================
S_StartBackgroundTrack
======================
*/
void SOrig_StartBackgroundTrack( const char *intro, const char *loop )
{
	if ( !intro )
	{
		intro = "";
	}

	if ( !loop || !loop[ 0 ] )
	{
		loop = intro;
	}

	Com_DPrintf( "S_StartBackgroundTrack( %s, %s )\n", intro, loop );

	if ( !intro[ 0 ] )
	{
		return;
	}

	Q_strncpyz( s_backgroundLoop, loop, sizeof( s_backgroundLoop ) );

	// close the background track, but DON'T reset s_rawend
	// if restarting the same back ground track
	if ( s_backgroundStream )
	{
		codec_close( s_backgroundStream );
		s_backgroundStream = NULL;
	}

	// Open stream
	s_backgroundStream = codec_open( intro );

	if ( !s_backgroundStream )
	{
		Com_DPrintf( S_COLOR_YELLOW  "WARNING: couldn't open music file %s\n", intro );
		return;
	}

	if ( s_backgroundStream->info.channels != 2 || s_backgroundStream->info.rate != 22050 )
	{
		Com_DPrintf( S_COLOR_YELLOW  "WARNING: music file %s is not 22k stereo\n", intro );
	}
}
Exemple #3
0
static void process_strm(u8_t *pkt, int len) {
	struct strm_packet *strm = (struct strm_packet *)pkt;

	LOG_INFO("strm command %c", strm->command);

	switch(strm->command) {
	case 't':
		sendSTAT("STMt", strm->replay_gain); // STMt replay_gain is no longer used to track latency, but support it
		break;
	case 'q':
		output_flush();
		status.frames_played = 0;
		stream_disconnect();
		sendSTAT("STMf", 0);
		buf_flush(streambuf);
		break;
	case 'f':
		output_flush();
		status.frames_played = 0;
		if (stream_disconnect()) {
			sendSTAT("STMf", 0);
		}
		buf_flush(streambuf);
		break;
	case 'p':
		{
			unsigned interval = unpackN(&strm->replay_gain);
			LOCK_O;
			output.pause_frames = interval * status.current_sample_rate / 1000;
			output.state = interval ? OUTPUT_PAUSE_FRAMES : OUTPUT_STOPPED;				
			UNLOCK_O;
			if (!interval) sendSTAT("STMp", 0);
			LOG_INFO("pause interval: %u", interval);
		}
		break;
	case 'a':
		{
			unsigned interval = unpackN(&strm->replay_gain);
			LOCK_O;
			output.skip_frames = interval * status.current_sample_rate / 1000;
			output.state = OUTPUT_SKIP_FRAMES;				
			UNLOCK_O;
			LOG_INFO("skip ahead interval: %u", interval);
		}
		break;
	case 'u':
		{
			unsigned jiffies = unpackN(&strm->replay_gain);
			LOCK_O;
			output.state = jiffies ? OUTPUT_START_AT : OUTPUT_RUNNING;
			output.start_at = jiffies;
			UNLOCK_O;
			LOCK_D;
			decode.state = DECODE_RUNNING;
			UNLOCK_D;
			LOG_INFO("unpause at: %u now: %u", jiffies, gettime_ms());
			sendSTAT("STMr", 0);
		}
		break;
	case 's':
		{
			unsigned header_len = len - sizeof(struct strm_packet);
			char *header = (char *)(pkt + sizeof(struct strm_packet));
			in_addr_t ip = (in_addr_t)strm->server_ip; // keep in network byte order
			u16_t port = strm->server_port; // keep in network byte order
			if (ip == 0) ip = slimproto_ip; 

			LOG_INFO("strm s autostart: %c transition period: %u transition type: %u", 
					 strm->autostart, strm->transition_period, strm->transition_type - '0');

			autostart = strm->autostart - '0';
			sendSTAT("STMf", 0);
			if (header_len > MAX_HEADER -1) {
				LOG_WARN("header too long: %u", header_len);
				break;
			}
			codec_open(strm->format, strm->pcm_sample_size, strm->pcm_sample_rate, strm->pcm_channels, strm->pcm_endianness);
			if (ip == LOCAL_PLAYER_IP && port == LOCAL_PLAYER_PORT) {
				// extension to slimproto for LocalPlayer - header is filename not http header, don't expect cont
				stream_file(header, header_len, strm->threshold * 1024);
				autostart -= 2;
			} else {
				stream_sock(ip, port, header, header_len, strm->threshold * 1024, autostart >= 2);
			}
			sendSTAT("STMc", 0);
			sentSTMu = sentSTMo = sentSTMl = false;
			LOCK_O;
			output.threshold = strm->output_threshold;
			output.next_replay_gain = unpackN(&strm->replay_gain);
			output.fade_mode = strm->transition_type - '0';
			output.fade_secs = strm->transition_period;
			LOG_INFO("set fade mode: %u", output.fade_mode);
			UNLOCK_O;
		}
		break;
	default:
		LOG_INFO("unhandled strm %c", strm->command);
		break;
	}
}