~ubuntu-branches/ubuntu/gutsy/amarok/gutsy-updates

« back to all changes in this revision

Viewing changes to amarok/src/engine/helix/helix-sp/helix-sp.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2006-11-03 23:57:33 UTC
  • mfrom: (1.31.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061103235733-a41oyfz4mzienqin
Tags: 2:1.4.4-0ubuntu2
Add debian/kubuntu-media-amarok and
debian amarok_play_audiocd.desktop for good KDE integration

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* **********
2
2
 *
3
3
 * This software is released under the provisions of the GPL version 2.
4
 
 * see file "COPYING".  If that file is not available, the full statement 
 
4
 * see file "COPYING".  If that file is not available, the full statement
5
5
 * of the license can be found at
6
6
 *
7
7
 * http://www.fsf.org/licensing/licenses/gpl.txt
70
70
class HelixSimplePlayerAudioStreamInfoResponse : public IHXAudioStreamInfoResponse
71
71
{
72
72
public:
73
 
   HelixSimplePlayerAudioStreamInfoResponse(HelixSimplePlayer *player, int playerIndex) : 
 
73
   HelixSimplePlayerAudioStreamInfoResponse(HelixSimplePlayer *player, int playerIndex) :
74
74
      m_Player(player), m_index(playerIndex), m_lRefCount(0) {}
75
75
   virtual ~HelixSimplePlayerAudioStreamInfoResponse() {}
76
76
 
80
80
   STDMETHOD(QueryInterface)   (THIS_
81
81
                               REFIID riid,
82
82
                               void** ppvObj);
83
 
    
 
83
 
84
84
   STDMETHOD_(ULONG32,AddRef)  (THIS);
85
85
 
86
86
   STDMETHOD_(ULONG32,Release) (THIS);
88
88
   /*
89
89
    * IHXAudioStreamInfoResponse methods
90
90
    */
91
 
   STDMETHOD(OnStream) (THIS_ 
 
91
   STDMETHOD(OnStream) (THIS_
92
92
                        IHXAudioStream *pAudioStream
93
93
                        );
94
94
private:
138
138
 
139
139
STDMETHODIMP HelixSimplePlayerAudioStreamInfoResponse::OnStream(IHXAudioStream *pAudioStream)
140
140
{
141
 
   m_Player->print2stderr("Stream Added on player %d, stream duration %ld, sources %d\n", m_index, 
 
141
   m_Player->print2stderr("Stream Added on player %d, stream duration %ld, sources %d\n", m_index,
142
142
                          m_Player->duration(m_index), m_Player->ppctrl[m_index]->pPlayer->GetSourceCount());
143
143
 
144
144
   m_Player->ppctrl[m_index]->pStream = pAudioStream;
145
 
   m_Player->ppctrl[m_index]->pPreMixHook = new HSPPreMixAudioHook(m_Player, m_index, pAudioStream, 
146
 
                                                                   m_Player->ppctrl[m_index]->bFadeIn, 
 
145
   m_Player->ppctrl[m_index]->pPreMixHook = new HSPPreMixAudioHook(m_Player, m_index, pAudioStream,
 
146
                                                                   m_Player->ppctrl[m_index]->bFadeIn,
147
147
                                                                   m_Player->ppctrl[m_index]->ulFadeLength);
148
148
 
149
149
   // addpremixhook adds another ref
150
150
   pAudioStream->AddPreMixHook(m_Player->ppctrl[m_index]->pPreMixHook, false);
151
 
   m_Player->ppctrl[m_index]->pPreMixHook->Release(); // release the ref added in the premixhook constructor 
 
151
   m_Player->ppctrl[m_index]->pPreMixHook->Release(); // release the ref added in the premixhook constructor
152
152
 
153
153
   m_Player->ppctrl[m_index]->bStarting = false;
154
154
 
167
167
//  Method:
168
168
//      IUnknown::QueryInterface
169
169
//  Purpose:
170
 
//      Implement this to export the interfaces supported by your 
 
170
//      Implement this to export the interfaces supported by your
171
171
//      object.
172
172
//
173
173
STDMETHODIMP HelixSimplePlayerVolumeAdvice::QueryInterface(REFIID riid, void** ppvObj)
244
244
    va_start(args, fmt);
245
245
 
246
246
    int ret = vsprintf(buf, fmt, args);
247
 
    std::cout << buf; 
 
247
    std::cout << buf;
248
248
 
249
249
    va_end(args);
250
250
 
307
307
{
308
308
   struct _HXxEvent *pNothing = 0x0;
309
309
   struct timeval    mtime;
310
 
   
 
310
 
311
311
   mtime.tv_sec  = 0;
312
312
   mtime.tv_usec = SLEEP_TIME * 1000;
313
313
   usleep(SLEEP_TIME*1000);
331
331
   gettimeofday(&t, NULL);
332
332
 
333
333
   // FIXME:
334
 
   // the fact that the result is bigger than a UINT32 is really irrelevant; 
 
334
   // the fact that the result is bigger than a UINT32 is really irrelevant;
335
335
   // we can still play a stream for many many years...
336
336
   return (UINT32)((t.tv_sec * 1000) + (t.tv_usec / 1000));
337
337
}
379
379
   m_outputsink(OSS),
380
380
   m_device(0),
381
381
#ifdef USE_HELIX_ALSA
382
 
   m_direct(ALSA),  // TODO: out why my alsa direct HW reader doesnt pickup changes in kmix (the whole purpose of this!)
 
382
   m_direct(ALSA),  // TODO: out why my alsa direct HW reader doesn't pickup changes in kmix (the whole purpose of this!)
383
383
#else
384
384
   m_direct(OSS),
385
385
#endif
482
482
         pPathNextPosition += ulBytesToCopy;
483
483
         ulBytesLeft -= ulBytesToCopy;
484
484
      }
485
 
      
 
485
 
486
486
      SafeSprintf(pNextPath, 256, "DT_Codecs=%s", codecshome);
487
487
      //print2stderr("Codec path %s\n", pNextPath );
488
488
      ulBytesToCopy = strlen(pNextPath) + 1;
495
495
      }
496
496
 
497
497
      fpSetDLLAccessPath((char*)pPaths);
498
 
       
 
498
 
499
499
      HX_VECTOR_DELETE(pNextPath);
500
500
   }
501
501
 
726
726
   }
727
727
   ppctrl[nNumPlayers]->pHSPContext->AddRef();
728
728
 
729
 
   //initialize the example context  
 
729
   //initialize the example context
730
730
 
731
731
   char pszGUID[GUID_LEN + 1]; /* Flawfinder: ignore */ // add 1 for terminator
732
732
   //char* token = NULL;
737
737
      theErr = HXR_FAILED;
738
738
      return -1;
739
739
   }
740
 
   
741
 
   pszGUID[0] = '\0';   
742
 
 
743
 
// disable for now - I dont know what I was thinking
 
740
 
 
741
   pszGUID[0] = '\0';
 
742
 
 
743
// disable for now - I don't know what I was thinking
744
744
#ifdef _DISABLE_CUZ_I_MUST_HAVE_BEEN_NUTS_
745
745
   if (m_pszGUIDList)
746
746
   {
760
760
      }
761
761
   }
762
762
#endif
763
 
   
 
763
 
764
764
   ppctrl[nNumPlayers]->pPlayer->QueryInterface(IID_IHXPreferences, (void**) &pPreferences);
765
765
   ppctrl[nNumPlayers]->pHSPContext->Init(ppctrl[nNumPlayers]->pPlayer, pPreferences, pszGUID);
766
766
   ppctrl[nNumPlayers]->pPlayer->SetClientContext(ppctrl[nNumPlayers]->pHSPContext);
767
767
   HX_RELEASE(pPreferences);
768
 
   
 
768
 
769
769
   ppctrl[nNumPlayers]->pPlayer->QueryInterface(IID_IHXErrorSinkControl, (void**) &pErrorSinkControl);
770
770
   if (pErrorSinkControl)
771
771
   {
774
774
         pErrorSinkControl->AddErrorSink(pErrorSink, HXLOG_EMERG, HXLOG_INFO);
775
775
      HX_RELEASE(pErrorSink);
776
776
   }
777
 
   
 
777
 
778
778
   HX_RELEASE(pErrorSinkControl);
779
779
 
780
780
   // Get the Player2 interface
781
781
   ppctrl[nNumPlayers]->pPlayer->QueryInterface(IID_IHXPlayer2, (void**) &ppctrl[nNumPlayers]->pPlayer2);
782
782
   if (!ppctrl[nNumPlayers]->pPlayer2)
783
783
      print2stderr("no player2 device\n");
784
 
   
 
784
 
785
785
   // Get the Audio Player
786
786
   ppctrl[nNumPlayers]->pPlayer->QueryInterface(IID_IHXAudioPlayer, (void**) &ppctrl[nNumPlayers]->pAudioPlayer);
787
787
   if (ppctrl[nNumPlayers]->pAudioPlayer)
891
891
         pEngine->ClosePlayer(ppctrl[i]->pPlayer);
892
892
         ppctrl[i]->pPlayer->Release();
893
893
      }
894
 
 
 
894
 
895
895
      delete ppctrl[i];
896
896
  }
897
897
 
966
966
   }
967
967
 
968
968
   closeAudioDevice();
969
 
   
 
969
 
970
970
   theErr = HXR_FAILED;
971
971
   pErrorSink = NULL;
972
972
   pErrorSinkControl = NULL;
978
978
   nNumPlayRepeats = 1;
979
979
   nTimeDelta = DEFAULT_TIME_DELTA;
980
980
   nStopTime = DEFAULT_STOP_TIME;
981
 
   bStopTime = true; 
 
981
   bStopTime = true;
982
982
   bStopping = false;
983
983
   nPlay = 0;
984
984
   bEnableAdviceSink = false;
995
995
}
996
996
 
997
997
 
998
 
void HelixSimplePlayer::setOutputSink( HelixSimplePlayer::AUDIOAPI out ) 
999
 
 
998
void HelixSimplePlayer::setOutputSink( HelixSimplePlayer::AUDIOAPI out )
 
999
{
1000
1000
#ifdef USE_HELIX_ALSA
1001
1001
   m_outputsink = out;
1002
1002
#else
1004
1004
#endif
1005
1005
}
1006
1006
 
1007
 
HelixSimplePlayer::AUDIOAPI HelixSimplePlayer::getOutputSink() 
1008
 
1009
 
   return m_outputsink; 
 
1007
HelixSimplePlayer::AUDIOAPI HelixSimplePlayer::getOutputSink()
 
1008
{
 
1009
   return m_outputsink;
1010
1010
}
1011
1011
 
1012
 
void HelixSimplePlayer::setDevice( const char *dev ) 
1013
 
 
1012
void HelixSimplePlayer::setDevice( const char *dev )
 
1013
{
1014
1014
   delete [] m_device;
1015
1015
 
1016
1016
   int len = strlen(dev);
1017
1017
   m_device = new char [len + 1];
1018
 
   strcpy(m_device, dev); 
 
1018
   strcpy(m_device, dev);
1019
1019
}
1020
1020
 
1021
 
const char *HelixSimplePlayer::getDevice() 
1022
 
1023
 
   return m_device; 
 
1021
const char *HelixSimplePlayer::getDevice()
 
1022
{
 
1023
   return m_device;
1024
1024
}
1025
1025
 
1026
1026
 
1035
1035
         //Check the environmental variable to let user overide default device.
1036
1036
         char *pszOverrideName = getenv( "AUDIO" ); /* Flawfinder: ignore */
1037
1037
         char szDevName[MAX_DEV_NAME]; /* Flawfinder: ignore */
1038
 
         
 
1038
 
1039
1039
         // Use defaults if no environment variable is set.
1040
1040
         if ( pszOverrideName && strlen(pszOverrideName)>0 )
1041
1041
         {
1045
1045
         {
1046
1046
            SafeStrCpy( szDevName, "/dev/mixer", MAX_DEV_NAME );
1047
1047
         }
1048
 
         
 
1048
 
1049
1049
         // Open the audio device if it isn't already open
1050
1050
         if ( m_nDevID < 0 )
1051
1051
         {
1052
1052
            m_nDevID = ::open( szDevName, O_WRONLY );
1053
1053
         }
1054
 
         
 
1054
 
1055
1055
         if ( m_nDevID < 0 )
1056
1056
         {
1057
1057
            print2stderr("Failed to open audio(%s)!!!!!!! Code is: %d  errno: %d\n",
1058
1058
                   szDevName, m_nDevID, errno );
1059
 
        
 
1059
 
1060
1060
            //Error opening device.
1061
1061
         }
1062
1062
      }
1066
1066
      {
1067
1067
#ifdef USE_HELIX_ALSA
1068
1068
         int err;
1069
 
         
 
1069
 
1070
1070
         print2stderr("Opening ALSA mixer device PCM\n");
1071
1071
 
1072
1072
         err = snd_mixer_open(&m_pAlsaMixerHandle, 0);
1073
1073
         if (err < 0)
1074
1074
            print2stderr("snd_mixer_open: %s\n", snd_strerror (err));
1075
 
  
 
1075
 
1076
1076
         if (err == 0)
1077
1077
         {
1078
1078
            err = snd_mixer_attach(m_pAlsaMixerHandle, m_alsaDevice);
1079
 
            if (err < 0) 
 
1079
            if (err < 0)
1080
1080
               print2stderr("snd_mixer_attach: %s\n", snd_strerror (err));
1081
1081
         }
1082
1082
 
1083
1083
         if (err == 0)
1084
1084
         {
1085
1085
            err = snd_mixer_selem_register(m_pAlsaMixerHandle, NULL, NULL);
1086
 
            if (err < 0) 
 
1086
            if (err < 0)
1087
1087
               print2stderr("snd_mixer_selem_register: %s\n", snd_strerror (err));
1088
1088
         }
1089
1089
 
1135
1135
            }
1136
1136
         }
1137
1137
 
1138
 
         
 
1138
 
1139
1139
         if (err != 0)
1140
1140
         {
1141
1141
            if(m_pAlsaMixerHandle)
1193
1193
            {
1194
1194
               err = snd_mixer_close(m_pAlsaMixerHandle);
1195
1195
               if(err < 0)
1196
 
                  print2stderr("snd_mixer_close: %s\n", snd_strerror (err));            
 
1196
                  print2stderr("snd_mixer_close: %s\n", snd_strerror (err));
1197
1197
            }
1198
 
            
 
1198
 
1199
1199
            if(err == 0)
1200
1200
            {
1201
1201
               m_pAlsaMixerHandle = NULL;
1212
1212
}
1213
1213
 
1214
1214
// it seems the master volume only gets reset on track change when using ALSA
1215
 
// sheez, I thought amaroK wasnt supposed to be a mixer??
 
1215
// sheez, I thought Amarok wasnt supposed to be a mixer??
1216
1216
// all this code is so that you can actually *use* a mixer and have it work
1217
1217
// the way you expect...
1218
1218
#ifdef USE_HELIX_ALSA
1227
1227
         if (!m_pAlsaMasterMixerElem)
1228
1228
            return nRetVolume;
1229
1229
 
1230
 
         snd_mixer_elem_type_t type;    
 
1230
         snd_mixer_elem_type_t type;
1231
1231
         int err = 0;
1232
1232
         type = snd_mixer_elem_get_type(m_pAlsaMasterMixerElem);
1233
 
            
 
1233
 
1234
1234
         if (type == SND_MIXER_ELEM_SIMPLE)
1235
1235
         {
1236
 
            long volumeL, volumeR, min_volume, max_volume; 
 
1236
            long volumeL, volumeR, min_volume, max_volume;
1237
1237
 
1238
 
            if(snd_mixer_selem_has_playback_volume(m_pAlsaMasterMixerElem) || 
 
1238
            if(snd_mixer_selem_has_playback_volume(m_pAlsaMasterMixerElem) ||
1239
1239
               snd_mixer_selem_has_playback_volume_joined(m_pAlsaMasterMixerElem))
1240
1240
            {
1241
1241
               err = snd_mixer_selem_get_playback_volume(m_pAlsaMasterMixerElem,
1242
 
                                                         SND_MIXER_SCHN_FRONT_LEFT, 
 
1242
                                                         SND_MIXER_SCHN_FRONT_LEFT,
1243
1243
                                                         &volumeL);
1244
1244
               if (err < 0)
1245
1245
                  print2stderr("snd_mixer_selem_get_playback_volume (L): %s\n", snd_strerror (err));
1246
1246
               else
1247
1247
               {
1248
 
                  if ( snd_mixer_selem_is_playback_mono ( m_pAlsaMasterMixerElem )) 
 
1248
                  if ( snd_mixer_selem_is_playback_mono ( m_pAlsaMasterMixerElem ))
1249
1249
                     volumeR = volumeL;
1250
1250
                  else
1251
1251
                  {
1252
1252
                     err = snd_mixer_selem_get_playback_volume(m_pAlsaMasterMixerElem,
1253
 
                                                               SND_MIXER_SCHN_FRONT_RIGHT, 
 
1253
                                                               SND_MIXER_SCHN_FRONT_RIGHT,
1254
1254
                                                               &volumeR);
1255
1255
                     if (err < 0)
1256
1256
                        print2stderr("snd_mixer_selem_get_playback_volume (R): %s\n", snd_strerror (err));
1257
1257
                  }
1258
1258
               }
1259
 
                  
 
1259
 
1260
1260
               if (err == 0)
1261
1261
               {
1262
1262
                  snd_mixer_selem_get_playback_volume_range(m_pAlsaMasterMixerElem,
1266
1266
                  if(max_volume > min_volume)
1267
1267
                     nRetVolume = (UINT16) (0.5 + (100.0 * (double)(volumeL + volumeR) / (2.0 * (max_volume - min_volume))));
1268
1268
               }
1269
 
            }        
 
1269
            }
1270
1270
         }
1271
1271
      }
1272
1272
      break;
1275
1275
         print2stderr("Unknown audio interface in getDirectMasterVolume()\n");
1276
1276
   }
1277
1277
 
1278
 
   return nRetVolume; 
 
1278
   return nRetVolume;
1279
1279
}
1280
1280
 
1281
1281
void HelixSimplePlayer::setDirectMasterVolume(int vol)
1287
1287
         if (!m_pAlsaMasterMixerElem)
1288
1288
            return;
1289
1289
 
1290
 
         snd_mixer_elem_type_t type;    
 
1290
         snd_mixer_elem_type_t type;
1291
1291
         int err = 0;
1292
1292
         type = snd_mixer_elem_get_type(m_pAlsaMasterMixerElem);
1293
1293
 
1294
 
         
 
1294
 
1295
1295
         if (type == SND_MIXER_ELEM_SIMPLE)
1296
1296
         {
1297
 
            long volume, min_volume, max_volume, range; 
1298
 
            
1299
 
            if(snd_mixer_selem_has_playback_volume(m_pAlsaMasterMixerElem) || 
 
1297
            long volume, min_volume, max_volume, range;
 
1298
 
 
1299
            if(snd_mixer_selem_has_playback_volume(m_pAlsaMasterMixerElem) ||
1300
1300
               snd_mixer_selem_has_playback_volume_joined(m_pAlsaMasterMixerElem))
1301
1301
            {
1302
1302
               snd_mixer_selem_get_playback_volume_range(m_pAlsaMasterMixerElem,
1303
1303
                                                         &min_volume,
1304
1304
                                                         &max_volume);
1305
 
               
 
1305
 
1306
1306
               range = max_volume - min_volume;
1307
1307
               volume = (long) (((double)vol / 100) * range + min_volume);
1308
1308
 
1309
1309
 
1310
1310
               err = snd_mixer_selem_set_playback_volume( m_pAlsaMasterMixerElem,
1311
 
                                                          SND_MIXER_SCHN_FRONT_LEFT, 
1312
 
                                                          volume);            
 
1311
                                                          SND_MIXER_SCHN_FRONT_LEFT,
 
1312
                                                          volume);
1313
1313
               if (err < 0)
1314
1314
                  print2stderr("snd_mixer_selem_set_playback_volume: %s\n", snd_strerror (err));
1315
1315
 
1317
1317
               {
1318
1318
                  /* Set the right channel too */
1319
1319
                  err = snd_mixer_selem_set_playback_volume( m_pAlsaMasterMixerElem,
1320
 
                                                             SND_MIXER_SCHN_FRONT_RIGHT, 
1321
 
                                                             volume);            
 
1320
                                                             SND_MIXER_SCHN_FRONT_RIGHT,
 
1321
                                                             volume);
1322
1322
                  if (err < 0)
1323
1323
                     print2stderr("snd_mixer_selem_set_playback_volume: %s\n", snd_strerror (err));
1324
1324
               }
1325
 
            }        
1326
 
         }    
 
1325
            }
 
1326
         }
1327
1327
      }
1328
1328
      break;
1329
1329
 
1344
1344
         int nVolume      = 0;
1345
1345
         int nLeftVolume  = 0;
1346
1346
         int nRightVolume = 0;
1347
 
    
 
1347
 
1348
1348
         if (m_nDevID < 0 || (::ioctl( m_nDevID, MIXER_READ(HX_VOLUME), &nVolume) < 0))
1349
1349
         {
1350
1350
            print2stderr("ioctl fails when reading HW volume: mnDevID=%d, errno=%d\n", m_nDevID, errno);
1352
1352
         }
1353
1353
         else
1354
1354
         {
1355
 
            nLeftVolume  = (nVolume & 0x000000ff); 
 
1355
            nLeftVolume  = (nVolume & 0x000000ff);
1356
1356
            nRightVolume = (nVolume & 0x0000ff00) >> 8;
1357
 
         
 
1357
 
1358
1358
            //Which one to use? Average them?
1359
1359
            nRetVolume = nLeftVolume ;
1360
1360
         }
1367
1367
         if (!m_pAlsaPCMMixerElem)
1368
1368
            return nRetVolume;
1369
1369
 
1370
 
         snd_mixer_elem_type_t type;    
 
1370
         snd_mixer_elem_type_t type;
1371
1371
         int err = 0;
1372
1372
         type = snd_mixer_elem_get_type(m_pAlsaPCMMixerElem);
1373
 
            
 
1373
 
1374
1374
         if (type == SND_MIXER_ELEM_SIMPLE)
1375
1375
         {
1376
 
            long volumeL, volumeR, min_volume, max_volume; 
 
1376
            long volumeL, volumeR, min_volume, max_volume;
1377
1377
 
1378
 
            if(snd_mixer_selem_has_playback_volume(m_pAlsaPCMMixerElem) || 
 
1378
            if(snd_mixer_selem_has_playback_volume(m_pAlsaPCMMixerElem) ||
1379
1379
               snd_mixer_selem_has_playback_volume_joined(m_pAlsaPCMMixerElem))
1380
1380
            {
1381
1381
               err = snd_mixer_selem_get_playback_volume(m_pAlsaPCMMixerElem,
1382
 
                                                         SND_MIXER_SCHN_FRONT_LEFT, 
 
1382
                                                         SND_MIXER_SCHN_FRONT_LEFT,
1383
1383
                                                         &volumeL);
1384
1384
               if (err < 0)
1385
1385
                  print2stderr("snd_mixer_selem_get_playback_volume (L): %s\n", snd_strerror (err));
1386
1386
               else
1387
1387
               {
1388
 
                  if ( snd_mixer_selem_is_playback_mono ( m_pAlsaPCMMixerElem )) 
 
1388
                  if ( snd_mixer_selem_is_playback_mono ( m_pAlsaPCMMixerElem ))
1389
1389
                     volumeR = volumeL;
1390
1390
                  else
1391
1391
                  {
1392
1392
                     err = snd_mixer_selem_get_playback_volume(m_pAlsaPCMMixerElem,
1393
 
                                                               SND_MIXER_SCHN_FRONT_RIGHT, 
 
1393
                                                               SND_MIXER_SCHN_FRONT_RIGHT,
1394
1394
                                                               &volumeR);
1395
1395
                     if (err < 0)
1396
1396
                        print2stderr("snd_mixer_selem_get_playback_volume (R): %s\n", snd_strerror (err));
1397
1397
                  }
1398
1398
               }
1399
 
                  
 
1399
 
1400
1400
               if (err == 0)
1401
1401
               {
1402
1402
                  snd_mixer_selem_get_playback_volume_range(m_pAlsaPCMMixerElem,
1406
1406
                  if(max_volume > min_volume)
1407
1407
                     nRetVolume = (UINT16) (0.5 + (100.0 * (double)(volumeL + volumeR) / (2.0 * (max_volume - min_volume))));
1408
1408
               }
1409
 
            }        
 
1409
            }
1410
1410
         }
1411
1411
#endif
1412
1412
      }
1416
1416
         print2stderr("Unknown audio interface in getDirectPCMVolume()\n");
1417
1417
   }
1418
1418
 
1419
 
   return nRetVolume; 
 
1419
   return nRetVolume;
1420
1420
}
1421
1421
 
1422
1422
void HelixSimplePlayer::setDirectPCMVolume(int vol)
1429
1429
 
1430
1430
         //Set both left and right volumes.
1431
1431
         nNewVolume = (vol & 0xff) | ((vol & 0xff) << 8);
1432
 
    
 
1432
 
1433
1433
         if (::ioctl( m_nDevID, MIXER_WRITE(HX_VOLUME), &nNewVolume) < 0)
1434
1434
            print2stderr("Unable to set direct HW volume\n");
1435
1435
      }
1441
1441
         if (!m_pAlsaPCMMixerElem)
1442
1442
            return;
1443
1443
 
1444
 
         snd_mixer_elem_type_t type;    
 
1444
         snd_mixer_elem_type_t type;
1445
1445
         int err = 0;
1446
1446
         type = snd_mixer_elem_get_type(m_pAlsaPCMMixerElem);
1447
1447
 
1448
 
         
 
1448
 
1449
1449
         if (type == SND_MIXER_ELEM_SIMPLE)
1450
1450
         {
1451
 
            long volume, min_volume, max_volume, range; 
1452
 
            
1453
 
            if(snd_mixer_selem_has_playback_volume(m_pAlsaPCMMixerElem) || 
 
1451
            long volume, min_volume, max_volume, range;
 
1452
 
 
1453
            if(snd_mixer_selem_has_playback_volume(m_pAlsaPCMMixerElem) ||
1454
1454
               snd_mixer_selem_has_playback_volume_joined(m_pAlsaPCMMixerElem))
1455
1455
            {
1456
1456
               snd_mixer_selem_get_playback_volume_range(m_pAlsaPCMMixerElem,
1457
1457
                                                         &min_volume,
1458
1458
                                                         &max_volume);
1459
 
               
 
1459
 
1460
1460
               range = max_volume - min_volume;
1461
1461
               volume = (long) (((double)vol / 100) * range + min_volume);
1462
1462
 
1463
1463
 
1464
1464
               err = snd_mixer_selem_set_playback_volume( m_pAlsaPCMMixerElem,
1465
 
                                                          SND_MIXER_SCHN_FRONT_LEFT, 
1466
 
                                                          volume);            
 
1465
                                                          SND_MIXER_SCHN_FRONT_LEFT,
 
1466
                                                          volume);
1467
1467
               if (err < 0)
1468
1468
                  print2stderr("snd_mixer_selem_set_playback_volume: %s\n", snd_strerror (err));
1469
1469
 
1471
1471
               {
1472
1472
                  /* Set the right channel too */
1473
1473
                  err = snd_mixer_selem_set_playback_volume( m_pAlsaPCMMixerElem,
1474
 
                                                             SND_MIXER_SCHN_FRONT_RIGHT, 
1475
 
                                                             volume);            
 
1474
                                                             SND_MIXER_SCHN_FRONT_RIGHT,
 
1475
                                                             volume);
1476
1476
                  if (err < 0)
1477
1477
                     print2stderr("snd_mixer_selem_set_playback_volume: %s\n", snd_strerror (err));
1478
1478
               }
1479
 
            }        
1480
 
         }    
 
1479
            }
 
1480
         }
1481
1481
#endif
1482
1482
      }
1483
1483
      break;
1493
1493
   if (playerIndex == ALL_PLAYERS)
1494
1494
   {
1495
1495
      int i;
1496
 
      
 
1496
 
1497
1497
      for (i=0; i<nNumPlayers; i++)
1498
1498
         setURL(file, i);
1499
1499
   }
1507
1507
 
1508
1508
      if (ppctrl[playerIndex]->pszURL)
1509
1509
         delete [] ppctrl[playerIndex]->pszURL;
1510
 
      
 
1510
 
1511
1511
      // see if the file is already in the form of a url
1512
1512
      char *tmp = strstr(file, "://");
1513
1513
      if (!tmp)
1514
1514
      {
1515
1515
         char pszURLOrig[MAXPATHLEN];
1516
1516
         const char* pszAddOn;
1517
 
         
 
1517
 
1518
1518
         strcpy(pszURLOrig, file);
1519
1519
         RemoveWrappingQuotes(pszURLOrig);
1520
1520
         pszAddOn = "file://";
1521
 
         
 
1521
 
1522
1522
         ppctrl[playerIndex]->pszURL = new char[strlen(pszURLOrig)+strlen(pszAddOn)+1];
1523
1523
         if ( (len + strlen(pszAddOn)) < MAXPATHLEN )
1524
1524
         {
1539
1539
 
1540
1540
      ppctrl[playerIndex]->isLocal = islocal;
1541
1541
 
1542
 
      print2stderr("opening %s on player %d, src cnt %d\n", 
 
1542
      print2stderr("opening %s on player %d, src cnt %d\n",
1543
1543
             ppctrl[playerIndex]->pszURL, playerIndex, ppctrl[playerIndex]->pPlayer->GetSourceCount());
1544
1544
 
1545
1545
#ifdef __NOCROSSFADER__
1546
1546
 
1547
1547
      if (HXR_OK == ppctrl[playerIndex]->pPlayer->OpenURL(ppctrl[playerIndex]->pszURL))
1548
1548
      {
1549
 
         print2stderr("opened player on %d src cnt %d\n", playerIndex, ppctrl[playerIndex]->pPlayer->GetSourceCount());         
 
1549
         print2stderr("opened player on %d src cnt %d\n", playerIndex, ppctrl[playerIndex]->pPlayer->GetSourceCount());
1550
1550
         m_urlchanged = true;
1551
1551
      }
1552
1552
#else
1565
1565
      pthread_mutex_unlock(&m_engine_m);
1566
1566
 
1567
1567
#endif
1568
 
      
 
1568
 
1569
1569
   }
1570
 
   
 
1570
 
1571
1571
   return 0;
1572
1572
}
1573
1573
 
1581
1581
   return 0;
1582
1582
}
1583
1583
 
1584
 
int HelixSimplePlayer::getPluginInfo(int index, 
1585
 
                                     const char *&description, 
1586
 
                                     const char *&copyright, 
 
1584
int HelixSimplePlayer::getPluginInfo(int index,
 
1585
                                     const char *&description,
 
1586
                                     const char *&copyright,
1587
1587
                                     const char *&moreinfourl) const
1588
1588
{
1589
1589
   if (index < m_numPlugins)
1591
1591
      description = m_pluginInfo[index]->description;
1592
1592
      copyright   = m_pluginInfo[index]->copyright;
1593
1593
      moreinfourl = m_pluginInfo[index]->moreinfourl;
1594
 
   
 
1594
 
1595
1595
      return 0;
1596
1596
   }
1597
1597
   return -1;
1609
1609
   int i;
1610
1610
   int firstPlayer = playerIndex == ALL_PLAYERS ? 0 : playerIndex;
1611
1611
   int lastPlayer  = playerIndex == ALL_PLAYERS ? nNumPlayers : playerIndex + 1;
1612
 
   
 
1612
 
1613
1613
   nPlay = 0;
1614
1614
   nNumPlayRepeats=1;
1615
 
   while(nPlay < nNumPlayRepeats) 
 
1615
   while(nPlay < nNumPlayRepeats)
1616
1616
   {
1617
1617
      nPlay++;
1618
1618
      if (bEnableVerboseMode)
1700
1700
         return;
1701
1701
 
1702
1702
      print2stderr("START MASTER VOL: %d\n",getDirectMasterVolume());
1703
 
      
 
1703
 
1704
1704
      if (bEnableVerboseMode)
1705
1705
      {
1706
1706
         print2stdout("Starting player %d...\n", playerIndex);
1799
1799
   struct _HXxEvent *pNothing = 0x0;
1800
1800
   struct timeval tv;
1801
1801
   int volAfter = 0;
1802
 
   
 
1802
 
1803
1803
   tv.tv_sec = 0;
1804
1804
   tv.tv_usec = SLEEP_TIME*1000;
1805
1805
 
1852
1852
void HelixSimplePlayer::pause(int playerIndex)
1853
1853
{
1854
1854
   int i;
1855
 
   
 
1855
 
1856
1856
   if (playerIndex == ALL_PLAYERS)
1857
1857
      for (i=0; i<nNumPlayers; i++)
1858
1858
         pause(i);
1869
1869
void HelixSimplePlayer::resume(int playerIndex)
1870
1870
{
1871
1871
   int i;
1872
 
   
 
1872
 
1873
1873
   if (playerIndex == ALL_PLAYERS)
1874
1874
      for (i=0; i<nNumPlayers; i++)
1875
1875
         resume(i);
1887
1887
void HelixSimplePlayer::seek(unsigned long pos, int playerIndex)
1888
1888
{
1889
1889
   int i;
1890
 
   
 
1890
 
1891
1891
   if (playerIndex == ALL_PLAYERS)
1892
1892
      for (i=0; i<nNumPlayers; i++)
1893
1893
         seek(pos, i);
1938
1938
void HelixSimplePlayer::setVolume(unsigned long vol, int playerIndex)
1939
1939
{
1940
1940
   int i;
1941
 
   
 
1941
 
1942
1942
   if (playerIndex == ALL_PLAYERS)
1943
1943
   {
1944
1944
      for (i=0; i<nNumPlayers; i++)
1961
1961
void HelixSimplePlayer::setMute(bool mute, int playerIndex)
1962
1962
{
1963
1963
   int i;
1964
 
   
 
1964
 
1965
1965
   if (playerIndex == ALL_PLAYERS)
1966
1966
   {
1967
1967
      for (i=0; i<nNumPlayers; i++)
1987
1987
      ismute = ppctrl[playerIndex]->ismute;
1988
1988
//pVolume->GetMute();
1989
1989
      pthread_mutex_unlock(&m_engine_m);
1990
 
      
 
1990
 
1991
1991
      return ismute;
1992
1992
   }
1993
1993
   else
2009
2009
         // Read in the entire file
2010
2010
         nNumRead = fread(pszBuffer, sizeof(char), readSize, pFile);
2011
2011
         pszBuffer[nNumRead] = '\0';
2012
 
         
 
2012
 
2013
2013
         // Store it for later parsing
2014
2014
         m_pszGUIDList = new char[nNumRead + 1];
2015
2015
         strcpy(m_pszGUIDList, pszBuffer); /* Flawfinder: ignore */
2016
 
         
 
2016
 
2017
2017
         fclose(pFile);
2018
2018
         pFile = NULL;
2019
2019
 
2025
2025
   }
2026
2026
 
2027
2027
   delete [] pszBuffer;
2028
 
   
 
2028
 
2029
2029
   return bSuccess;
2030
2030
}
2031
2031
 
2032
2032
 
2033
 
void HelixSimplePlayer::addScopeBuf(struct DelayQueue *item, int playerIndex) 
 
2033
void HelixSimplePlayer::addScopeBuf(struct DelayQueue *item, int playerIndex)
2034
2034
{
2035
2035
   if (playerIndex >=0 && playerIndex < nNumPlayers)
2036
2036
   {
2037
2037
      pthread_mutex_lock(&ppctrl[playerIndex]->m_scope_m);
2038
 
   
 
2038
 
2039
2039
      if (ppctrl[playerIndex]->scopebuftail)
2040
2040
      {
2041
2041
         item->fwd = 0;
2059
2059
   if (playerIndex >=0 && playerIndex < nNumPlayers)
2060
2060
   {
2061
2061
      pthread_mutex_lock(&ppctrl[playerIndex]->m_scope_m);
2062
 
   
 
2062
 
2063
2063
      struct DelayQueue *item = ppctrl[playerIndex]->scopebufhead;
2064
 
   
 
2064
 
2065
2065
      if (item)
2066
2066
      {
2067
2067
         ppctrl[playerIndex]->scopebufhead = item->fwd;
2069
2069
         if (!ppctrl[playerIndex]->scopebufhead)
2070
2070
            ppctrl[playerIndex]->scopebuftail = 0;
2071
2071
      }
2072
 
      
 
2072
 
2073
2073
      pthread_mutex_unlock(&ppctrl[playerIndex]->m_scope_m);
2074
 
      
 
2074
 
2075
2075
      return item;
2076
2076
   }
2077
2077
   else
2078
2078
      return 0;
2079
2079
}
2080
2080
 
2081
 
int HelixSimplePlayer::peekScopeTime(unsigned long &t, int playerIndex) 
 
2081
int HelixSimplePlayer::peekScopeTime(unsigned long &t, int playerIndex)
2082
2082
{
2083
2083
   if (playerIndex >=0 && playerIndex < nNumPlayers)
2084
2084
   {