BE: Fix 'MythSocket: Programmer error, QEventLoop isn't running...' during BE exit

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
Fix compilation warnings
Mythframe: fix cpuid for Mingw32

Patch by Lawrence Rust <lvr@softsystem.co.uk>
Fix 0b9470c Fix fileringbuffer locking...

Commit 0b9470c (Fix fileringbuffer locking up on read()) modified
FileRingBuffer::safe_read to use fstat() to check the file size
before reading.  The new code compares (internalreadpos + tot)
with the reported size.  This is mostly correct except when
MythPlayer::SwitchProgram detects the transition across a livetv
programme boundary.  In this case internalreadpos holds the read
position for the old file until the decoder calls FileChanged().

This patch includes readAdjust (set by SetAdjustFilesize()) to
correctly determine the current read position in the file.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
VO: Fail VAAPI reinit from decoder thread to avoid Qt abort in doneCurrent

If a recording starts without a video stream then if the video
subsequently becomes active the decoder attempts to re-init the
display.  However, the OpenGL functions fail if called outside of the
UI thread and this results in an unbalanced series of calls to
doneCurrebt which triggers a Qt abort (debug build) due to a recursive
mutex overflow.

This bug is tickled by the CloseShave video which started recording
at just before 7pm on BBC3, which is just before the start of normal
BBC prgrams.  The initial stream consists of MHEG data only.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
Player: Increase OpenFile timeout to allow playing encrypted isos on a remote FE

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
AFD: Read packets until audio PTS >= video PTS

If the 'Extra audio buffering' setting is disabled then the audio
stream PTS can lag the video by up to a second.  This can sometimes
cause A/V sync problems but also causes sync problems when displaying
the audio output graph when editing the cutlist.

This patch ensures that the last audio PTS at least equals the video
PTS before exiting GetFrame.  This ensures there are matching audio
samples for the pause frame shown in the cutlkist editor.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
TV: Quit the TV playback loop when the primary player reports a fatal error

If MythPlayer::OpenFile fails (for instance network congestion) then
TV::StartTV continues by restarting TV instance which then causes problems
for the backend.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
Player: DecoderLoop sleeps until audio buffers available

DVB radio streams (e.g. UK FreeView & FreeSat) burn 100% CPU time when
playing back a recording.

This patch adds a 1mS sleep loop until the audio buffer has space
available.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
CoreContext: Add missing QRunnable header

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
AO: SetStretchFactor sets pause until buffered to smooth playback start

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
AO: Pause resets PauseUntilBuffered

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
TV UnpauseLiveTV calls tvchain->SwitchTo opposed to JumpTo to minimise visible disruption

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
AO: Don't disable Pulse if no valid output

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
AO: Cache the result of IsPulseAudioRunning

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
OpenGL: Reduce video playback overhead

This patch introduces 2 changes to reduce video frame overhead and
hence reduce CPU load.

1. In MythRenderOpenGL::doneCurrent don't call QGLContext::doneCurrent
as it's strictly not necessary and causes the next call to makeCurrent
to take considerably longer.  Saves ~ 11mS per frame.

2. In VideoOutputOpenGL::Show only call gl_context->swapBuffers if
the current format is double buffered,  Saves ~2mS per frame.

Timings from an Intel i5 661 @ 3.33GHz using onboard graphics with
Linux 3.4 KMS.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
libmyth: Prevent SEGV in avcodec_decode_video2 when playing nuv material

Under certain circumstances NuppelDecoder::DecodeFrame can call
avcodec_decode_video2 when mpa_vidctx is NULL and thus cause a SEGV.

This patch adds a test for a NULL mpa_vidctx exits with error.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
Player: Improve low bit rate / high latency stream playback

DVB-S radio programs are low bit rate (64Kbps..256Kbps) and suffer
occasional latency.

MHEG interaction streams are internet sourced and often suffer congestion
resulting in high latency for some packets.

- Fix a number of issues to do with changing program to DVB-S radio and
  the lack of video stream causing garbage video display.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
Player: Don't call DoneDisplayingFrame for PiP until next frame is ready

When displaying 'pictute in picture' (PiP), VideoOutput::ShowPIP
composites the PiP windows onto the main video frame.  To do so, it uses
the player's GetCurrentFrame method to obtain the most recently displayed
PiP frame.  However, MythPlayer::DisplayNormalFrames immediately releases
the last frame displayed back to the decoding queue.  Consequently when
GetCurrentFrame calls GetLastShownFrame to obtain that frame it may have been
overwritten by the decoder thread.

This patch defers calling DoneDisplayingFrame if the player is a PiP
player so that future calls to GetLastShownFrame return an intact frame.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>
OSD: Add a graphical display of audio level to cut list editor

When using the cut list editor to remove ads etc it's difficult to place
the cut precisely when the program is faded in or out.  In these cases
it's common to cut the dialogue or retain voice-overs.  It's also
impossible to create a cut list for DVB radio recordings.

This patch adds a visual graph of the audio level +/-0.5 frame around the
current paused frame.

Add a mutex to guard access by the decoder and UI threads

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
Signed-off-by: Jean-Yves Avenard <jyavenard@mythtv.org>