From 206f9ae13ac20084210d296aed427aafdc4e1a3c Mon Sep 17 00:00:00 2001
From: Lawrence Rust <lvr@softsystem.co.uk>
Date: Fri, 27 May 2011 20:15:15 +0200
Subject: [PATCH 38/42] mythplayer: Avoid stutters between programs and when changing channel.
This reverts part of commit 08a8a65535638de185e68f76898c118161d4bf88
(Force reload of context and stream properties when switching between LiveTV)
and reorders some code to reduce interference with RingBuffer prefetching
and decoding.
I can't reproduce (on DVB-S) the problems that commit 08a8a655 is supposed to
fix and the disruption to program switching it causes is very annoying.
Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
---
mythtv/libs/libmythtv/mythplayer.cpp | 82 ++++++++++++++--------------------
1 files changed, 33 insertions(+), 49 deletions(-)
diff --git a/mythtv/libs/libmythtv/mythplayer.cpp b/mythtv/libs/libmythtv/mythplayer.cpp
index e3219db..3233b96 100644
a
|
b
|
void MythPlayer::SwitchToProgram(void) |
2186 | 2186 | VERBOSE(VB_PLAYBACK, LOC + "SwitchToProgram - start"); |
2187 | 2187 | bool discontinuity = false, newtype = false; |
2188 | 2188 | int newid = -1; |
2189 | | ProgramInfo *pginfo = player_ctx->tvchain->GetSwitchProgram( |
2190 | | discontinuity, newtype, newid); |
| 2189 | QSharedPointer<ProgramInfo> pginfo(player_ctx->tvchain->GetSwitchProgram( |
| 2190 | discontinuity, newtype, newid)); |
2191 | 2191 | if (!pginfo) |
2192 | 2192 | return; |
2193 | | newtype = true; // force reloading of context and stream properties |
2194 | 2193 | |
2195 | 2194 | bool newIsDummy = player_ctx->tvchain->GetCardType(newid) == "DUMMY"; |
2196 | 2195 | |
2197 | 2196 | SetPlayingInfo(*pginfo); |
2198 | | Pause(); |
2199 | | ChangeSpeed(); |
2200 | 2197 | |
2201 | 2198 | if (newIsDummy) |
2202 | 2199 | { |
2203 | 2200 | OpenDummy(); |
2204 | 2201 | ResetPlaying(); |
2205 | 2202 | SetEof(false); |
2206 | | delete pginfo; |
2207 | 2203 | return; |
2208 | 2204 | } |
2209 | 2205 | |
… |
… |
void MythPlayer::SwitchToProgram(void) |
2218 | 2214 | VERBOSE(VB_IMPORTANT, QString("\n") + player_ctx->tvchain->toString()); |
2219 | 2215 | SetEof(true); |
2220 | 2216 | SetErrored(QObject::tr("Error opening switch program buffer")); |
2221 | | delete pginfo; |
2222 | 2217 | return; |
2223 | 2218 | } |
2224 | 2219 | |
2225 | 2220 | if (GetEof()) |
2226 | | { |
2227 | 2221 | discontinuity = true; |
2228 | | ResetCaptions(); |
2229 | | } |
2230 | 2222 | |
2231 | 2223 | VERBOSE(VB_PLAYBACK, LOC + QString("SwitchToProgram(void) " |
2232 | 2224 | "discont: %1 newtype: %2 newid: %3 decoderEof: %4") |
… |
… |
void MythPlayer::SwitchToProgram(void) |
2234 | 2226 | |
2235 | 2227 | if (discontinuity || newtype) |
2236 | 2228 | { |
2237 | | player_ctx->tvchain->SetProgram(*pginfo); |
2238 | | if (decoder) |
2239 | | decoder->SetProgramInfo(*pginfo); |
| 2229 | Pause(); |
| 2230 | ChangeSpeed(); |
| 2231 | ResetCaptions(); |
2240 | 2232 | |
| 2233 | player_ctx->tvchain->SetProgram(*pginfo); |
2241 | 2234 | player_ctx->buffer->Reset(true); |
| 2235 | |
2242 | 2236 | if (newtype) |
2243 | 2237 | { |
2244 | 2238 | if (OpenFile() < 0) |
… |
… |
void MythPlayer::SwitchToProgram(void) |
2246 | 2240 | } |
2247 | 2241 | else |
2248 | 2242 | ResetPlaying(); |
| 2243 | |
| 2244 | if (IsErrored()) |
| 2245 | { |
| 2246 | VERBOSE(VB_IMPORTANT, LOC_ERR + "SwitchToProgram failed."); |
| 2247 | SetEof(true); |
| 2248 | return; |
| 2249 | } |
| 2250 | |
| 2251 | SetEof(false); |
| 2252 | |
| 2253 | if (decoder) |
| 2254 | { |
| 2255 | // the bitrate is reset by player_ctx->buffer->OpenFile()... |
| 2256 | player_ctx->buffer->UpdateRawBitrate(decoder->GetRawBitrate()); |
| 2257 | decoder->SetProgramInfo(*pginfo); |
| 2258 | } |
| 2259 | |
| 2260 | CheckTVChain(); |
| 2261 | forcePositionMapSync = true; |
| 2262 | Play(); |
2249 | 2263 | } |
2250 | 2264 | else |
2251 | 2265 | { |
2252 | 2266 | player_ctx->SetPlayerChangingBuffers(true); |
2253 | 2267 | if (decoder) |
2254 | 2268 | { |
| 2269 | // the bitrate is reset by player_ctx->buffer->OpenFile()... |
| 2270 | player_ctx->buffer->UpdateRawBitrate(decoder->GetRawBitrate()); |
2255 | 2271 | decoder->SetReadAdjust(player_ctx->buffer->SetAdjustFilesize()); |
2256 | 2272 | decoder->SetWaitForChange(); |
2257 | 2273 | } |
2258 | 2274 | } |
2259 | | delete pginfo; |
2260 | | |
2261 | | if (IsErrored()) |
2262 | | { |
2263 | | VERBOSE(VB_IMPORTANT, LOC_ERR + "SwitchToProgram failed."); |
2264 | | SetEof(true); |
2265 | | return; |
2266 | | } |
2267 | | |
2268 | | SetEof(false); |
2269 | | |
2270 | | // the bitrate is reset by player_ctx->buffer->OpenFile()... |
2271 | | if (decoder) |
2272 | | player_ctx->buffer->UpdateRawBitrate(decoder->GetRawBitrate()); |
2273 | | player_ctx->buffer->Unpause(); |
2274 | | |
2275 | | if (discontinuity || newtype) |
2276 | | { |
2277 | | CheckTVChain(); |
2278 | | forcePositionMapSync = true; |
2279 | | } |
2280 | 2275 | |
2281 | | Play(); |
2282 | 2276 | VERBOSE(VB_PLAYBACK, LOC + "SwitchToProgram - end"); |
2283 | 2277 | } |
2284 | 2278 | |
… |
… |
void MythPlayer::FileChangedCallback(void) |
2286 | 2280 | { |
2287 | 2281 | VERBOSE(VB_PLAYBACK, LOC + "FileChangedCallback"); |
2288 | 2282 | |
2289 | | Pause(); |
2290 | 2283 | ChangeSpeed(); |
2291 | | if (dynamic_cast<AvFormatDecoder *>(decoder)) |
2292 | | player_ctx->buffer->Reset(false, true); |
2293 | | else |
2294 | | player_ctx->buffer->Reset(false, true, true); |
2295 | | SetEof(false); |
2296 | | Play(); |
| 2284 | player_ctx->buffer->Reset(false, false, true); |
2297 | 2285 | |
2298 | 2286 | player_ctx->SetPlayerChangingBuffers(false); |
2299 | 2287 | |
… |
… |
void MythPlayer::JumpToProgram(void) |
2313 | 2301 | bool discontinuity = false, newtype = false; |
2314 | 2302 | int newid = -1; |
2315 | 2303 | long long nextpos = player_ctx->tvchain->GetJumpPos(); |
2316 | | ProgramInfo *pginfo = player_ctx->tvchain->GetSwitchProgram( |
2317 | | discontinuity, newtype, newid); |
| 2304 | QSharedPointer<ProgramInfo> pginfo(player_ctx->tvchain->GetSwitchProgram( |
| 2305 | discontinuity, newtype, newid)); |
2318 | 2306 | if (!pginfo) |
2319 | 2307 | return; |
2320 | 2308 | newtype = true; // force reloading of context and stream properties |
… |
… |
void MythPlayer::JumpToProgram(void) |
2333 | 2321 | OpenDummy(); |
2334 | 2322 | ResetPlaying(); |
2335 | 2323 | SetEof(false); |
2336 | | delete pginfo; |
2337 | 2324 | return; |
2338 | 2325 | } |
2339 | 2326 | |
2340 | | SendMythSystemPlayEvent("PLAY_CHANGED", pginfo); |
| 2327 | SendMythSystemPlayEvent("PLAY_CHANGED", pginfo.data()); |
2341 | 2328 | |
2342 | 2329 | player_ctx->buffer->OpenFile( |
2343 | 2330 | pginfo->GetPlaybackURL(), RingBuffer::kLiveTVOpenTimeout); |
… |
… |
void MythPlayer::JumpToProgram(void) |
2350 | 2337 | VERBOSE(VB_IMPORTANT, QString("\n") + player_ctx->tvchain->toString()); |
2351 | 2338 | SetEof(true); |
2352 | 2339 | SetErrored(QObject::tr("Error opening jump program file buffer")); |
2353 | | delete pginfo; |
2354 | 2340 | return; |
2355 | 2341 | } |
2356 | 2342 | |
… |
… |
void MythPlayer::JumpToProgram(void) |
2368 | 2354 | VERBOSE(VB_IMPORTANT, LOC_ERR + "JumpToProgram failed."); |
2369 | 2355 | if (!IsErrored()) |
2370 | 2356 | SetErrored(QObject::tr("Error reopening video decoder")); |
2371 | | delete pginfo; |
2372 | 2357 | return; |
2373 | 2358 | } |
2374 | 2359 | |
… |
… |
void MythPlayer::JumpToProgram(void) |
2379 | 2364 | player_ctx->buffer->IgnoreLiveEOF(false); |
2380 | 2365 | |
2381 | 2366 | decoder->SetProgramInfo(*pginfo); |
2382 | | delete pginfo; |
2383 | 2367 | |
2384 | 2368 | CheckTVChain(); |
2385 | 2369 | forcePositionMapSync = true; |