Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes
nsSound Class Reference

#include <nsSound.h>

Inheritance diagram for nsSound:
Inheritance graph
[legend]
Collaboration diagram for nsSound:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsSound ()
virtual ~nsSound ()
 nsSound ()
virtual ~nsSound ()
 nsSound ()
virtual ~nsSound ()
 nsSound ()
virtual ~nsSound ()
NS_DECL_ISUPPORTS
NS_DECL_NSISOUND nsresult 
AddRequest (nsISupports *aSoundRequest)
nsresult RemoveRequest (nsISupports *aSoundRequest)
nsresult GetCacheSession (nsICacheSession **outCacheSession)
nsresult GetSoundFromCache (nsIURI *inURI, nsISupports **outSound)
nsresult PutSoundInCache (nsIChannel *inChannel, PRUint32 inDataSize, nsISupports *inSound)
 nsSound ()
virtual ~nsSound ()
 nsSound ()
virtual ~nsSound ()
 nsSound ()
virtual ~nsSound ()
 nsSound ()
virtual ~nsSound ()
 nsSound ()
virtual ~nsSound ()
void play (in nsIURL aURL)
void playSystemSound (in string soundAlias)
 for playing system sounds
void beep ()
void init ()
 Not strictly necessary, but avoids delay before first sound.
void onStreamComplete (in nsIStreamLoader loader, in nsISupports ctxt, in nsresult status, in unsigned long resultLength,[const, array, size_is(resultLength)] in octet result)

Protected Member Functions

nsresult GetSoundResourceName (const char *inSoundName, StringPtr outResourceName)

Protected Attributes

nsSupportsArray mSoundRequests

Private Member Functions

void PurgeLastSound ()

Private Attributes

BSimpleGameSound * mSound
PRBool mInited
PRUint8mLastSound

Detailed Description

Definition at line 46 of file nsSound.h.


Constructor & Destructor Documentation

Definition at line 64 of file nsSound.cpp.

 : mSound(0)
{
}
nsSound::~nsSound ( ) [virtual]

Definition at line 69 of file nsSound.cpp.

{
       Init();
}

Here is the call graph for this function:

virtual nsSound::~nsSound ( ) [virtual]
virtual nsSound::~nsSound ( ) [virtual]
virtual nsSound::~nsSound ( ) [virtual]
virtual nsSound::~nsSound ( ) [virtual]
virtual nsSound::~nsSound ( ) [virtual]
virtual nsSound::~nsSound ( ) [virtual]
virtual nsSound::~nsSound ( ) [virtual]
virtual nsSound::~nsSound ( ) [virtual]

Member Function Documentation

nsresult nsSound::AddRequest ( nsISupports *  aSoundRequest)

Definition at line 304 of file nsSound.cpp.

{
  // only add if not already in the list
  PRInt32   index = mSoundRequests.IndexOf(aSoundRequest);
  if (index == -1)
  {
    nsresult  appended = mSoundRequests.AppendElement(aSoundRequest);
    if (!appended)
      return NS_ERROR_FAILURE;
  }
  
  return NS_OK;
}
void nsISound::beep ( ) [inherited]

Definition at line 331 of file nsSound.cpp.

{
  nsresult rv;

  nsCOMPtr<nsICacheService> cacheService = do_GetService("@mozilla.org/network/cache-service;1", &rv);
  if (NS_FAILED(rv)) return rv;
  
  return cacheService->CreateSession("sound",
                              nsICache::STORE_IN_MEMORY,
                              nsICache::NOT_STREAM_BASED, outCacheSession);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsSound::GetSoundFromCache ( nsIURI inURI,
nsISupports **  outSound 
)

Definition at line 345 of file nsSound.cpp.

{
  nsresult rv;
  
  nsCAutoString uriSpec;
  inURI->GetAsciiSpec(uriSpec);

  nsCOMPtr<nsICacheSession> cacheSession;
  rv = GetCacheSession(getter_AddRefs(cacheSession));
  if (NS_FAILED(rv)) return rv;
  
  nsCOMPtr<nsICacheEntryDescriptor> entry;
  rv = cacheSession->OpenCacheEntry(uriSpec, nsICache::ACCESS_READ, nsICache::BLOCKING, getter_AddRefs(entry));

#ifdef SOUND_DEBUG
  printf("Got sound from cache with rv %ld\n", rv);
#endif

  if (NS_FAILED(rv)) return rv;
  
  return entry->GetCacheElement(outSound);
}

Here is the call graph for this function:

nsresult nsSound::GetSoundResourceName ( const char *  inSoundName,
StringPtr  outResourceName 
) [protected]

Definition at line 431 of file nsSound.cpp.

{
  nsresult rv = NS_OK;
  
  outResourceName[0] = 0;
  
  // if it's the special mail beep sound, get the real sound name from IC
  if (nsCRT::strcmp("_moz_mailbeep", inSoundName) == 0)
  {
    nsCOMPtr <nsIInternetConfigService> icService = do_GetService(NS_INTERNETCONFIGSERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv))
      return rv;
    
    nsCAutoString  newMailSound;
    rv = icService->GetString(nsIInternetConfigService::eICString_NewMailSoundName, newMailSound);
    if (NS_FAILED(rv))
      return rv;
      
    CopyCToPascalString(newMailSound.get(), outResourceName);
    return NS_OK;
  }

  // if the name is not "Mailbeep", treat it as the name of a system sound
  CopyCToPascalString(inSoundName, outResourceName);
  return NS_OK;
}

Here is the call graph for this function:

void nsISound::init ( ) [inherited]

Not strictly necessary, but avoids delay before first sound.

The various methods on nsISound call Init() if they need to.

void nsIStreamLoaderObserver::onStreamComplete ( in nsIStreamLoader  loader,
in nsISupports  ctxt,
in nsresult  status,
in unsigned long  resultLength,
[const, array, size_is(resultLength)] in octet  result 
) [inherited]
void nsISound::play ( in nsIURL  aURL) [inherited]
void nsISound::playSystemSound ( in string  soundAlias) [inherited]

for playing system sounds

Definition at line 111 of file nsSound.cpp.

                             {
  if (mLastSound) {
    // Purge the current sound buffer.
    CWinMM& theMM = CWinMM::GetModule();
    theMM.PlaySound(nsnull, nsnull, SND_PURGE); // This call halts the sound if it was still playing.

    // Now delete the buffer.
    free(mLastSound);
    mLastSound = nsnull;
  }
}

Here is the call graph for this function:

nsresult nsSound::PutSoundInCache ( nsIChannel inChannel,
PRUint32  inDataSize,
nsISupports *  inSound 
)

Definition at line 370 of file nsSound.cpp.

{
  nsresult rv;
  
  NS_ENSURE_ARG(inChannel && inSound);
  
  nsCOMPtr<nsIURI>  uri;
  inChannel->GetOriginalURI(getter_AddRefs(uri));
  if (!uri) return NS_ERROR_FAILURE;
  
  nsCAutoString uriSpec;
  rv = uri->GetAsciiSpec(uriSpec);
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsICacheSession> cacheSession;
  rv = GetCacheSession(getter_AddRefs(cacheSession));
  if (NS_FAILED(rv)) return rv;

  nsCOMPtr<nsICacheEntryDescriptor> entry;
  rv = cacheSession->OpenCacheEntry(uriSpec, nsICache::ACCESS_WRITE, nsICache::BLOCKING, getter_AddRefs(entry));
#ifdef SOUND_DEBUG
  printf("Put sound in cache with rv %ld\n", rv);
#endif

  if (NS_FAILED(rv)) return rv;

  rv = entry->SetCacheElement(inSound);
  if (NS_FAILED(rv)) return rv;

  rv = entry->SetDataSize(inDataSize);
  if (NS_FAILED(rv)) return rv;
  
  PRUint32    expirationTime = 0;

  // try to get the expiration time from the URI load
  nsCOMPtr<nsICachingChannel> cachingChannel = do_QueryInterface(inChannel);
  if (cachingChannel)
  {
    nsCOMPtr<nsISupports> cacheToken;
    cachingChannel->GetCacheToken(getter_AddRefs(cacheToken));
    nsCOMPtr<nsICacheEntryInfo> cacheEntryInfo = do_QueryInterface(cacheToken);
    if (cacheEntryInfo)
    {
      cacheEntryInfo->GetExpirationTime(&expirationTime);
    }
  }
  
  if (expirationTime == PRUint32(-1))   // no expiration time (never expires)
  {
    // set it to some reasonable default, like now + 24 hours
    expirationTime = SecondsFromPRTime(PR_Now()) + 60 * 60 * 24;
  }
  
  rv = entry->SetExpirationTime(expirationTime);
  if (NS_FAILED(rv)) return rv;
  
  return entry->MarkValid();
}

Here is the call graph for this function:

nsresult nsSound::RemoveRequest ( nsISupports *  aSoundRequest)

Definition at line 320 of file nsSound.cpp.

{
  nsresult  removed = mSoundRequests.RemoveElement(aSoundRequest);
  if (!removed)
    return NS_ERROR_FAILURE;

  return NS_OK;
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 61 of file nsSound.h.

Definition at line 62 of file nsSound.h.

BSimpleGameSound* nsSound::mSound [private]

Definition at line 57 of file nsSound.h.

nsSupportsArray nsSound::mSoundRequests [protected]

Definition at line 71 of file nsSound.h.


The documentation for this class was generated from the following files: