Kodi Community Forum

Full Version: XBMC with alsa: No sound on playing video files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi!

I'm using XBMC almost latest git version on gentoo.

There is a known issue and a solution for a receiver connected via HDMI to start playing sound a second or two after a song starts playing in XBMC. This leads to a "cut-off" a second of the song while listening.

The solution is to play silence all the time to make reciever be ready to play sound at any time.
I personally do this via
Code:
/usr/bin/aplay -c6 -r192000 -fS24_LE  < /dev/zero > /dev/null 2>&1 &
This solution is not the ideal since it uses dmixer to output sound which resamples audio.

Since
Code:
cat /proc/asound/NVidia/eld#3.0

shows this:
Code:
monitor_present         1
eld_valid               1
monitor_name            DENON-AVAMP

connection_type         HDMI
eld_version             [0x2] CEA-861D or below
edid_version            [0x3] CEA-861-B, C or D
manufacture_id          0xee11
product_id              0x1d
port_id                 0x20000
support_hdcp            0
support_ai              0
audio_sync_delay        0
speakers                [0x5f] FL/FR LFE FC RL/RR RC RLC/RRC
sad_count               7
sad0_coding_type        [0x1] LPCM
sad0_channels           8
sad0_rates              [0x1ee0] 44100 48000 88200 176400 192000 384000
sad0_bits               [0xe0000] 16 20 24
sad1_coding_type        [0x7] DTS
sad1_channels           6
sad1_rates              [0x6c0] 48000 88200 176400 192000
sad1_max_bitrate        1536000
sad2_coding_type        [0x2] AC-3
sad2_channels           6
sad2_rates              [0xe0] 44100 48000 88200
sad2_max_bitrate        640000
sad3_coding_type        [0xb] DTS-HD
sad3_channels           8
sad3_rates              [0x1ec0] 48000 88200 176400 192000 384000
sad4_coding_type        [0xa] E-AC-3/DD+ (Dolby Digital Plus)
sad4_channels           8
sad4_rates              [0xc0] 48000 88200
sad5_coding_type        [0xc] MLP (Dolby TrueHD)
sad5_channels           6
sad5_rates              [0x1ec0] 48000 88200 176400 192000 384000
sad6_coding_type        [0xc] MLP (Dolby TrueHD)
sad6_channels           8
sad6_rates              [0x6c0] 48000 88200 176400 192000

I made such alsa configuration in /etc/asound.conf
Code:
pcm.dmixer {
  type dmix;
  ipc_key 2048;
  ipc_key_add_uid 0;
  ipc_perm 0660 # IPC permissions (octal, default 0600)
  slave {
    pcm "hw:0,9"; # Always use pure hw. dmix will reformat/resample audio.
    channels 6;
    #period_time 0;
    period_size 512;
    #buffer_time 0;
    buffer_size 8192;
    #buffer_size 4096;
    #rate 96000;
    rate 192000;
    format S24_LE;
  }
}

pcm.plugequal {
  type equal;
#  slave.pcm "plughw:0,9";
  slave.pcm "plug:dmixer";
#  channels 6;
}

pcm.!surround51 {
  type asym;
#  type plug;
#  slave.pcm "hw:0,9";
#  slave.pcm plugequal;
  playback.pcm "dmixer";
#  slave.pcm "plug:dmixer";
#  slave.channels 6;
}

pcm.!default {
  type plug;
#  slave.pcm "hw:0,9";
  slave.pcm plugequal;
#  slave.pcm "plug:dmixer";
#  slave.channels 6;
}

ctl.equal {
  type equal;
}

#defaults.pcm.rate_converter "samplerate_best"

BTW does anyone know what are period_size and buffer_size here?

And this solves the audio "cut-off" problem when playing any song (I have normal 44100Hz flacs and 98000Hz ones).I also want equalizer to process my audio so I use alsaequal.
Since dmixer is set up to use 6 channels playing 5.1 audio signal is also ok.

But when playing video with sound - sound does not play! ("Failed to initialize audio device" is displayed)

XBMC log starts being filled with messages like
Code:
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 7798, consumed: 2707
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2867, consumed: 7798
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 7144, consumed: 2867
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2663, consumed: 7144
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 7650, consumed: 2663
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2635, consumed: 7650
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2631, consumed: 2635
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 7105, consumed: 2631
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2472, consumed: 7105
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2476, consumed: 2472
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 6240, consumed: 2476
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2459, consumed: 6240
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2406, consumed: 2459
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 7278, consumed: 2406
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2291, consumed: 7278
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 3320, consumed: 2291
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 7024, consumed: 3320
12:08:38 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2368, consumed: 7024

Sound in video is mp3 48000Hz 2 channels (stereo)
I have disabled DTS and Ac3 audio passthrough since I want to be able regulate volume while playing video as well.

Video starts playing if I change dmix settings to use 48000 hz instead of 192000. I also tried 98000 but with no luck.

Setting 48000 Hz in dmixer is not an option as with this being set 98000Hz flacs do not play and cause XBMC to hang.

In advancedsettings.xml I have an option for audio since the default music player remaps 5.1 sound channels and this remap is different than in video player (which is strange!)
Code:
<advancedsettings>
        <audio>
                <!-- Default audio player: paplayer or dvdplayer (or mplayer on Xbox) -->
                <defaultplayer>dvdplayer</defaultplayer>
        </audio>
</advancedsettings>

Can anyone help with this? How can I make video files to play audio signal with current settings in alsa conf?

Maybe I can somehow avoid using dmixer as it definitely leads to loss in sound quality and still make a receiver to be ready? (Windows somehow does this!) This would even be a better solution.

Thanks!
Here is the start of the log when playing video fails to play sound:

Code:
12:02:48 T:139750208046912  NOTICE: DVDPlayer: Opening: /media/video/Medium 4/medium.s04e09.dvdrip.rus.eng.novafilm.tv.avi
12:02:48 T:139750208046912 WARNING: CDVDMessageQueue(player)::Put MSGQ_NOT_INITIALIZED
12:02:48 T:139749602940672  NOTICE: Creating InputStream
12:02:48 T:139749602940672  NOTICE: Creating Demuxer
12:02:48 T:139749602940672  NOTICE: Opening video stream: 0 source: 256
12:02:48 T:139749602940672  NOTICE: Creating video codec with codec id: 13
12:02:48 T:139749602940672  NOTICE: CDVDVideoCodecFFmpeg::Open() Using codec: MPEG-4 part 2
12:02:48 T:139749602940672  NOTICE: Creating video thread
12:02:48 T:139749602940672  NOTICE: Opening audio stream: 1 source: 256
12:02:48 T:139749602940672  NOTICE: Finding audio codec for: 86017
12:02:48 T:139749602940672  NOTICE: Creating audio thread
12:02:48 T:139749569369856  NOTICE: running thread: video_thread
12:02:48 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 2411, consumed: 0
12:02:48 T:139749560977152  NOTICE: running thread: CDVDPlayerAudio::Process()
12:02:48 T:139749560977152  NOTICE: Creating audio device with codec id: 86017, channels: 2, sample rate: 48000, no pass-through
12:02:48 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 116, consumed: 2411
12:02:48 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 9, consumed: 116
12:02:48 T:139749569369856  NOTICE:  fps: 23.976024, pwidth: 624, pheight: 352, dwidth: 624, dheight: 352
12:02:48 T:139749569369856  NOTICE: Display resolution ADJUST : default: 1920x1080 @ 24.00Hz (14) (weight: 0.001)
12:02:48 T:139750208046912  NOTICE: Using GL_TEXTURE_2D
12:02:48 T:139750208046912  NOTICE: GL: Selecting Single Pass YUV 2 RGB shader
12:02:48 T:139750208046912  NOTICE: GL: NPOT texture support detected
12:02:48 T:139750208046912  NOTICE: GL: Using GL_ARB_pixel_buffer_object
12:02:49 T:139750208046912   ERROR: GLX: Same window as before, refreshing context
12:02:50 T:139749569369856 WARNING: CRenderManager::FlipPage - timeout waiting for flip to complete
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 116, consumed: 9
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 9, consumed: 116
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 116, consumed: 9
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 9, consumed: 116
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 116, consumed: 9
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 9, consumed: 116
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 116, consumed: 9
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 9, consumed: 116
12:02:50 T:139749569369856 WARNING: Decode - avcodec_decode_video didn't consume the full packet. size: 116, consumed: 9

Also I just noticed that the previous log line of the "Decode - avcodec_decode_video didn't consume the full packet. size:" has the value that is "consumed" in the next line!
Ok, I tested Pulseaudio. Did a redirect to pulse from alsa and then back from pulse to hw device via alsa sink. That solves the problem. But software mixing makes me crazy. It eats a lot of CPU if I want to use 96khz sampling rate. Also if another app starts eating CPU sound starts cracking which is not what I want to end up with =(

So the best solution would be to add a possibility to add a delay before a song starts to play in XBMC. No quality loss because of upsampling and to heavy CPU usage - just let the receiver do what it can do with each one's sample rate and achieve the best possible quality.

How can I add a delay before a songHuh Anyone?