Author: fejj
Date: 2008-01-17 12:50:05 -0500 (Thu, 17 Jan 2008)
New Revision: 93178
Modified:
trunk/moon/src/ChangeLog
trunk/moon/src/mplayer2.cpp
Log:
2008-01-17 Jeffrey Stedfast <[EMAIL PROTECTED]>
* mplayer2.cpp (audio_decode): Removed as it is no longer really
needed.
(audio_loop): We can't assume that an entire decoded audio packet
will fit into the audio output buffer in a single shot, break it
up if needed.
Modified: trunk/moon/src/ChangeLog
===================================================================
--- trunk/moon/src/ChangeLog 2008-01-17 17:44:04 UTC (rev 93177)
+++ trunk/moon/src/ChangeLog 2008-01-17 17:50:05 UTC (rev 93178)
@@ -1,3 +1,11 @@
+2008-01-17 Jeffrey Stedfast <[EMAIL PROTECTED]>
+
+ * mplayer2.cpp (audio_decode): Removed as it is no longer really
+ needed.
+ (audio_loop): We can't assume that an entire decoded audio packet
+ will fit into the audio output buffer in a single shot, break it
+ up if needed.
+
2008-01-17 Rolf Bjarne Kvinge <[EMAIL PROTECTED]>
* mplayer2.cpp: Max out video frame rate at 60fps.
Modified: trunk/moon/src/mplayer2.cpp
===================================================================
--- trunk/moon/src/mplayer2.cpp 2008-01-17 17:44:04 UTC (rev 93177)
+++ trunk/moon/src/mplayer2.cpp 2008-01-17 17:50:05 UTC (rev 93178)
@@ -50,7 +50,6 @@
#define AUDIO_BUFLEN (AVCODEC_MAX_AUDIO_FRAME_SIZE * 2)
static uint64_t audio_play (Audio *audio, bool play, struct pollfd *ufds, int
nfds);
-static bool audio_decode (Audio *audio);
static void *audio_loop (void *data);
extern guint32 moonlight_flags;
@@ -81,11 +80,6 @@
pthread_mutex_t init_mutex;
pthread_cond_t init_cond;
- // Packet left from previous decode loop
- Packet *pkt;
- uint32_t inleft;
- uint8_t *inptr;
-
double balance;
double volume;
bool muted;
@@ -119,10 +113,6 @@
queue = new Queue ();
- pkt = NULL;
- inleft = 0;
- inptr = NULL;
-
balance = 0.0f;
volume = 1.0f;
muted = false;
@@ -266,7 +256,7 @@
{
MediaFrame *frame;
int states, i;
-
+
if (mplayer->HasAudio ()) {
for (i = 0; i < audio_frames; i++) {
frame = new MediaFrame (mplayer->audio->stream);
@@ -750,15 +740,6 @@
audio_thread = NULL;
}
- // de-queue audio/video packets
- if (audio->pkt != NULL) {
- delete audio->pkt;
- audio->pkt = NULL;
-
- audio->inptr = NULL;
- audio->inleft = 0;
- }
-
audio->queue->Clear (true);
video->queue->Clear (true);
@@ -820,6 +801,9 @@
} else if (HasVideo ()) {
duration = video->stream->duration;
initial_pts = video->stream->start_time;
+ } else {
+ initial_pts = 0;
+ duration = 0;
}
duration += initial_pts;
@@ -974,56 +958,6 @@
// Audio playback thread
-//// Returns true if finished decoding, false otherwise
-static bool
-audio_decode (Audio *audio)
-{
- int32_t frame_size = audio->sample_size * audio->stream->channels * 2;
- uint8_t *outbuf;
- int outlen = 0;
- int n;
-
- /* Note: an audio packet can contain multiple audio frames */
-
- while (audio->inleft > 0) {
- // TODO: Remove alignment
- outbuf = ALIGN (audio->outptr, 2);
- outlen = (audio->outbuf + AUDIO_BUFLEN) - outbuf;
-
- memcpy (outbuf, audio->inptr, audio->inleft);
- //printf ("audio_decode (), copied %i bytes.\n", audio->inleft);
- n = audio->inleft;
-
- if (n > 0) {
- audio->inleft -= n;
- audio->inptr += n;
-
- // append the newly decoded buffer to the end of the
- // remaining audio buffer from our previous loop
- // (if re-alignment was required).
- if (outbuf > audio->outptr) {
- //printf ("audio_decode (): memmove, outbuf:
%p, outlen: %p\n", outbuf, outlen);
- memmove (audio->outptr, outbuf, outlen);
- }
- audio->outptr += n;
- } else if (n == 0) {
- /* complete or out of room in outbuf */
- break;
- } else {
- //printf ("audio_decode error: %d\n", n);
- // pad frame with silence
- if ((n = (audio->outptr - audio->outbuf) % frame_size)
> 0) {
- memset (audio->outptr, 0, n);
- audio->outptr += n;
- }
-
- return true;
- }
- }
-
- return audio->inleft == 0;
-}
-
static int
pcm_poll (snd_pcm_t *pcm, struct pollfd *ufds, int nfds)
{
@@ -1161,17 +1095,24 @@
static void *
audio_loop (void *data)
{
- //printf ("audio_loop (): started.\n");
MediaPlayer *mplayer = (MediaPlayer *) data;
Audio *audio = mplayer->audio;
struct pollfd *ufds = NULL;
IMediaStream *stream;
uint64_t frame_pts;
+ Packet *pkt = NULL;
MediaFrame *frame;
- Packet *pkt;
+ uint8_t *outend;
+ uint32_t inleft;
+ uint8_t *inptr;
+ uint32_t n;
bool play;
int ndfs;
+ outend = audio->outbuf + AUDIO_BUFLEN;
+ inptr = NULL;
+ inleft = 0;
+
pthread_mutex_lock (&mplayer->audio->init_mutex);
if ((ndfs = snd_pcm_poll_descriptors_count (audio->pcm)) > 0) {
@@ -1212,39 +1153,58 @@
pthread_mutex_unlock (&mplayer->target_pts_lock);
//printf ("calculated target_pts = %llu (frame_pts:
%lld)\n", mplayer->target_pts, frame_pts);
} else {
- // decode an audio packet
- if (!audio->pkt && (pkt = (Packet *) audio->queue->Pop
())) {
+ if (!pkt && (pkt = (Packet *) audio->queue->Pop ())) {
+ // decode an audio packet
stream = pkt->frame->stream;
frame = pkt->frame;
- if (!frame->IsDecoded ()) {
- if (!MEDIA_SUCCEEDED
(stream->decoder->DecodeFrame (frame)))
- continue;
- }
+ if (!frame->IsDecoded ())
+ stream->decoder->DecodeFrame (frame);
- audio->inleft = frame->uncompressed_size;
- audio->inptr = (uint8_t *)
frame->uncompressed_data;
- audio->pkt = pkt;
-
pthread_mutex_lock (&mplayer->target_pts_lock);
mplayer->target_pts = frame->pts;
pthread_mutex_unlock
(&mplayer->target_pts_lock);
//printf ("setting target_pts to %llu\n",
mplayer->target_pts);
- media_player_enqueue_frames (mplayer, 1, 0);
- //printf ("audio_loop, popped a packet, %i
packets left. inleft: %i, inptr: %p\n", audio->queue->Length (), audio->inleft,
audio->inptr);
- if (!audio_decode (audio))
- printf ("audio_loop (), decode
failed.\n");
+ inptr = (uint8_t *) frame->uncompressed_data;
+ inleft = frame->uncompressed_size;
- delete audio->pkt;
- audio->pkt = NULL;
+ media_player_enqueue_frames (mplayer, 1, 0);
+ } else if (!pkt) {
+ // need to either wait for a packet to
+ // be queued or break if the audio
+ // stream is complete...
}
+ if (pkt != NULL) {
+ // calculate how much room in the output buffer
we have
+ n = (outend - audio->outptr);
+
+ if (inleft <= n) {
+ // blit the remainder of the
decompressed audio frame
+ memcpy (audio->outptr, inptr, inleft);
+ audio->outptr += inleft;
+
+ inptr = NULL;
+ inleft = 0;
+ delete pkt;
+ pkt = NULL;
+ } else {
+ // blit what we can...
+ memcpy (audio->outptr, inptr, n);
+ audio->outptr += n;
+ inleft -= n;
+ inptr += n;
+ }
+ }
}
}
//printf ("audio_loop (): exited.\n");
+ if (pkt != NULL)
+ delete pkt;
+
pthread_mutex_unlock (&mplayer->pause_mutex);
g_free (ufds);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches