#
# Copyright (C) by Stefano Falsetto
# e-mail contact ....: mailto:stefko5@inwind.it
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# Config plugin for ogg123
#

cat_variables_ogg123 () {
    cat <<EOF 
# Complete path for ogg decoder
ogg123_DECODER="$ogg123_DECODER"

# Params to only show a time line
OGG_EXTRACT_TIME="$OGG_EXTRACT_TIME"

# Parameters to output to stdout with buffered mode
OGG_BUFFERED_DECODE="$OGG_BUFFERED_DECODE"

# Parameters to output to stdout without buffer
OGG_DECODE_TO_STDOUT="$OGG_DECODE_TO_STDOUT"

# Parameters to simply decode
OGG_NORMALDECODE="$OGG_NORMALDECODE"

# Parameters to output to file in wav format
OGG_TO_wav="$OGG_TO_wav"

# Parameters to output to file in raw format
OGG_TO_raw="$OGG_TO_wav"

# Array of supported output formats files
OUTPUT_FORMATS_ogg123=( $OUTPUT_FORMATS_ogg123 )

# default output file format
OGG_TOFMT="$OGG_TOFMT"

# Default conversion file extension
OGG_MPGCMD="$OGG_MPGCMD"


EOF
}


############
# MAIN
############

if [ $(expr "$SUPPORTED_FORMATS" : ".*ogg.*") -ne ${#SUPPORTED_FORMATS} ]; then
  begin_check ogg123
  find_prg ogg123
  ogg123_DECODER=$FOUND_PRG

  if [ -z "$ogg123_DECODER" ]; then
    missing ogg123 "http://www.xiph.org/ogg/vorbis"
  else
    QueryVersion $($ogg123_DECODER -V 2>&1|cut -d' ' -f4) ogg123 "1.0beta4"
    echo
    find_prg strings
    if [ -z "$FOUND_PRG" ]; then
      find_prg strings-GNU 
      if [ -z "$FOUND_PRG" ]; then
        missing strings-GNU "http://www.gnu.org/software/binutils/binutils.html"
        unset ogg123_DECODER
        exit
      fi
    fi
    
    EXTENSIONS="ogg"
    OGG_EXTRACT_TIME=" -v -d null -k 9999999 "
    OGG_BUFFERED_DECODE=" -q -v -b 4 -d oss -o dsp:/dev/stdout" 
    OGG_DECODE_TO_STDOUT="-q -v -d oss -o dsp:/dev/stdout"
    OGG_NORMALDECODE=" -q -v "
    OUTPUT_FORMATS_ogg123="wav raw"
    OGG_TO_wav="-d wav -o file:"
    OGG_TO_raw="-d oss -o dsp:/dev/stdout"
    OGG_TOFMT=$OGG_TO_wav
    OGG_MPGCMD="wav"
    AUDIO_PLUGINS="$AUDIO_PLUGINS ogg123"
    SUPPORTED_FORMATS="$SUPPORTED_FORMATS $EXTENSIONS"
    lechoc CYAN $"Summary of command used by $ogg123_DECODER:"
    lechoc YELLOW " -> $ogg123_DECODER $OGG_EXTRACT_TIME song.ogg"
    lechoc CYAN $"Buffered decode:"
    lechoc YELLOW " -> $ogg123_DECODER $OGG_BUFFERED_DECODE song.ogg | ..."
    lechoc CYAN $"Decoding to stdout:"
    lechoc YELLOW " -> $ogg123_DECODER $OGG_DECODE_TO_STDOUT song.ogg | ..."
    lechoc CYAN $"Normal decoding to wav (default):"
    lechoc YELLOW " -> $ogg123_DECODER $OGG_NORMALDECODE ${OGG_TO_wav}filename.wav song.ogg"
    lechoc CYAN $"Normal decoding to raw:"
    lechoc YELLOW " -> $ogg123_DECODER $OGG_NORMALDECODE song.ogg ${OGG_TO_raw} >filename.wav"


    end_check
  fi
fi

