Skip to content

Commit 5976c15

Browse files
authored
Merge pull request #11 from mfat/testing
Testing to main
2 parents dd5dbd9 + bb774fa commit 5976c15

File tree

1 file changed

+91
-18
lines changed

1 file changed

+91
-18
lines changed

tvhplayer/tvhplayer.py

Lines changed: 91 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,7 @@ def __init__(self):
889889
self.recording_animation = None
890890
self.opacity_effect = None
891891

892-
# Initialize VLC
892+
# Initialize VLC with basic instance first
893893
print("Debug: Initializing VLC instance")
894894
try:
895895
if getattr(sys, 'frozen', False):
@@ -906,12 +906,21 @@ def __init__(self):
906906

907907
print(f"Debug: VLC plugin path set to: {plugin_path}")
908908

909-
# Initialize VLC without arguments
910-
self.instance = vlc.Instance()
909+
# Initialize VLC with hardware acceleration parameters
910+
vlc_args = [
911+
# Enable hardware decoding
912+
'--avcodec-hw=any', # Try any hardware acceleration method
913+
'--file-caching=1000', # Increase file caching for smoother playback
914+
'--network-caching=1000', # Increase network caching for streaming
915+
'--no-video-title-show', # Don't show the video title
916+
'--no-snapshot-preview', # Don't show snapshot previews
917+
]
918+
919+
self.instance = vlc.Instance(vlc_args)
911920
if not self.instance:
912921
raise RuntimeError("VLC Instance creation returned None")
913922

914-
print("Debug: VLC instance created successfully")
923+
print("Debug: VLC instance created successfully with hardware acceleration")
915924

916925
self.media_player = self.instance.media_player_new()
917926
if not self.media_player:
@@ -923,26 +932,44 @@ def __init__(self):
923932
print(f"Error initializing VLC: {str(e)}")
924933
raise RuntimeError(f"Failed to initialize VLC: {str(e)}")
925934

926-
927-
928935
# Then setup UI
929936
self.setup_ui()
930937

931938
# Update to use config for last server
932939
self.server_combo.setCurrentIndex(self.config.get('last_server', 0))
933940

934-
#Set player window - with proper type conversion
935-
936-
if sys.platform.startswith('linux'):
937-
handle = self.video_frame.winId().__int__()
938-
if handle is not None:
939-
self.media_player.set_xwindow(handle)
940-
elif sys.platform == "win32":
941-
self.media_player.set_hwnd(self.video_frame.winId().__int__())
942-
elif sys.platform == "darwin":
943-
self.media_player.set_nsobject(self.video_frame.winId().__int__())
944-
945-
941+
# Now configure hardware acceleration after UI is set up
942+
try:
943+
# Set player window - with proper type conversion
944+
if sys.platform.startswith('linux'):
945+
handle = self.video_frame.winId().__int__()
946+
if handle is not None:
947+
self.media_player.set_xwindow(handle)
948+
elif sys.platform == "win32":
949+
self.media_player.set_hwnd(self.video_frame.winId().__int__())
950+
elif sys.platform == "darwin":
951+
self.media_player.set_nsobject(self.video_frame.winId().__int__())
952+
953+
# Set hardware decoding to automatic
954+
if hasattr(self.media_player, 'set_hardware_decoding'):
955+
self.media_player.set_hardware_decoding(True)
956+
else:
957+
# Alternative method for older VLC Python bindings
958+
self.media_player.video_set_key_input(False)
959+
self.media_player.video_set_mouse_input(False)
960+
961+
# Add a timer to check which hardware acceleration method is being used
962+
# This will check after playback starts
963+
self.hw_check_timer = QTimer()
964+
self.hw_check_timer.setSingleShot(True)
965+
self.hw_check_timer.timeout.connect(self.check_hardware_acceleration)
966+
self.hw_check_timer.start(5000) # Check after 5 seconds of playback
967+
968+
print("Debug: Hardware acceleration configured for VLC")
969+
970+
except Exception as e:
971+
print(f"Warning: Could not configure hardware acceleration: {str(e)}")
972+
print("Continuing without hardware acceleration")
946973

947974
def setup_paths(self):
948975
"""Setup application paths for resources"""
@@ -2528,6 +2555,52 @@ def filter_channels(self, search_text):
25282555
channel_name = item.text().lower()
25292556
self.channel_list.setRowHidden(row, search_text not in channel_name)
25302557

2558+
def check_hardware_acceleration(self):
2559+
"""Check and print which hardware acceleration method is being used"""
2560+
if not self.media_player:
2561+
return
2562+
2563+
# This only works if a media is playing
2564+
if not self.media_player.is_playing():
2565+
return
2566+
2567+
try:
2568+
# Get media statistics - handle different VLC Python binding versions
2569+
media = self.media_player.get_media()
2570+
if not media:
2571+
print("No media currently playing")
2572+
return
2573+
2574+
# Different versions of python-vlc have different APIs for get_stats
2575+
try:
2576+
# Newer versions (direct call)
2577+
stats = media.get_stats()
2578+
print("VLC Playback Statistics:")
2579+
print(f"Decoded video blocks: {stats.decoded_video}")
2580+
print(f"Displayed pictures: {stats.displayed_pictures}")
2581+
print(f"Lost pictures: {stats.lost_pictures}")
2582+
except TypeError:
2583+
# Older versions (requiring a stats object parameter)
2584+
stats = vlc.MediaStats()
2585+
media.get_stats(stats)
2586+
print("VLC Playback Statistics:")
2587+
print(f"Decoded video blocks: {stats.decoded_video}")
2588+
print(f"Displayed pictures: {stats.displayed_pictures}")
2589+
print(f"Lost pictures: {stats.lost_pictures}")
2590+
2591+
# Check if hardware decoding is enabled
2592+
if hasattr(self.media_player, 'get_role'):
2593+
print(f"Media player role: {self.media_player.get_role()}")
2594+
2595+
# Try to get more detailed hardware acceleration info
2596+
print("Hardware acceleration is active if you see 'Using ... for hardware decoding' in the logs above")
2597+
print("For more details, run VLC with the same content and use:")
2598+
print("Tools -> Messages -> Info to see which decoder is being used")
2599+
2600+
except Exception as e:
2601+
print(f"Error checking hardware acceleration: {e}")
2602+
print(f"Traceback: {traceback.format_exc()}")
2603+
25312604

25322605

25332606
class EPGDialog(QDialog):

0 commit comments

Comments
 (0)