示例#1
0
nsresult MediaPluginReader::ReadMetadata(MediaInfo* aInfo,
                                         MetadataTags** aTags)
{
  NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");

  if (!mPlugin) {
    mPlugin = GetMediaPluginHost()->CreateDecoder(mDecoder->GetResource(), mType);
    if (!mPlugin) {
      return NS_ERROR_FAILURE;
    }
  }

  // Set the total duration (the max of the audio and video track).
  int64_t durationUs;
  mPlugin->GetDuration(mPlugin, &durationUs);
  if (durationUs) {
    ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
    mDecoder->SetMediaDuration(durationUs);
  }

  if (mPlugin->HasVideo(mPlugin)) {
    int32_t width, height;
    mPlugin->GetVideoParameters(mPlugin, &width, &height);
    nsIntRect pictureRect(0, 0, width, height);

    // Validate the container-reported frame and pictureRect sizes. This ensures
    // that our video frame creation code doesn't overflow.
    nsIntSize displaySize(width, height);
    nsIntSize frameSize(width, height);
    if (!VideoInfo::ValidateVideoRegion(frameSize, pictureRect, displaySize)) {
      return NS_ERROR_FAILURE;
    }

    // Video track's frame sizes will not overflow. Activate the video track.
    mHasVideo = mInfo.mVideo.mHasVideo = true;
    mInfo.mVideo.mDisplay = displaySize;
    mPicture = pictureRect;
    mInitialFrame = frameSize;
    VideoFrameContainer* container = mDecoder->GetVideoFrameContainer();
    if (container) {
      container->SetCurrentFrame(gfxIntSize(displaySize.width, displaySize.height),
                                 nullptr,
                                 mozilla::TimeStamp::Now());
    }
  }

  if (mPlugin->HasAudio(mPlugin)) {
    int32_t numChannels, sampleRate;
    mPlugin->GetAudioParameters(mPlugin, &numChannels, &sampleRate);
    mHasAudio = mInfo.mAudio.mHasAudio = true;
    mInfo.mAudio.mChannels = numChannels;
    mInfo.mAudio.mRate = sampleRate;
  }

 *aInfo = mInfo;
 *aTags = nullptr;
  return NS_OK;
}
/* static */
already_AddRefed<MediaDecoder>
DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
{
  nsRefPtr<MediaDecoder> decoder;

#ifdef MOZ_GSTREAMER
  if (IsGStreamerSupportedType(aType)) {
    decoder = new GStreamerDecoder();
  }
#endif
#ifdef MOZ_RAW
  if (IsRawType(aType)) {
    decoder = new RawDecoder();
  }
#endif
#ifdef MOZ_OGG
  if (IsOggType(aType)) {
    decoder = new OggDecoder();
  }
#endif
#ifdef MOZ_WAVE
  if (IsWaveType(aType)) {
    decoder = new WaveDecoder();
  }
#endif
#ifdef MOZ_WIDGET_GONK
  if (IsOmxSupportedType(aType)) {
    decoder = new MediaOmxDecoder();
  }
#endif
#ifdef MOZ_MEDIA_PLUGINS
  if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, NULL)) {
    decoder = new MediaPluginDecoder(aType);
  }
#endif
#ifdef MOZ_WEBM
  if (IsWebMType(aType)) {
    decoder = new WebMDecoder();
  }
#endif
#ifdef MOZ_DASH
  if (IsDASHMPDType(aType)) {
    decoder = new DASHDecoder();
  }
#endif
#ifdef MOZ_WMF
  if (IsWMFSupportedType(aType)) {
    decoder = new WMFDecoder();
  }
#endif

  NS_ENSURE_TRUE(decoder != nullptr, nullptr);
  NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);

  return decoder.forget();
}
示例#3
0
// Resets all state related to decoding, emptying all buffers etc.
nsresult MediaPluginReader::ResetDecode()
{
  if (mLastVideoFrame) {
    mLastVideoFrame = nullptr;
  }
  if (mPlugin) {
    GetMediaPluginHost()->DestroyDecoder(mPlugin);
    mPlugin = nullptr;
  }

  return NS_OK;
}
/* static */
MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
{
  MediaDecoderReader* decoderReader = nullptr;

#ifdef MOZ_GSTREAMER
  if (IsGStreamerSupportedType(aType)) {
    decoderReader = new GStreamerReader(aDecoder);
  } else
#endif
#ifdef MOZ_RAW
  if (IsRawType(aType)) {
    decoderReader = new RawReader(aDecoder);
  } else
#endif
#ifdef MOZ_OGG
  if (IsOggType(aType)) {
    decoderReader = new OggReader(aDecoder);
  } else
#endif
#ifdef MOZ_WAVE
  if (IsWaveType(aType)) {
    decoderReader = new WaveReader(aDecoder);
  } else
#endif
#ifdef MOZ_WIDGET_GONK
  if (IsOmxSupportedType(aType)) {
    decoderReader = new MediaOmxReader(aDecoder);
  } else
#endif
#ifdef MOZ_MEDIA_PLUGINS
  if (MediaDecoder::IsMediaPluginsEnabled() &&
      GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
    decoderReader = new MediaPluginReader(aDecoder, aType);
  } else
#endif
#ifdef MOZ_WEBM
  if (IsWebMType(aType)) {
    decoderReader = new WebMReader(aDecoder);
  } else
#endif
#ifdef MOZ_WMF
  if (IsWMFSupportedType(aType)) {
    decoderReader = new WMFReader(aDecoder);
  } else
#endif
#ifdef MOZ_DASH
  // The DASH decoder is not supported.
#endif
  if (false) {} // dummy if to take care of the dangling else

  return decoderReader;
}
// Resets all state related to decoding, emptying all buffers etc.
nsresult MediaPluginReader::ResetDecode()
{
  if (mLastVideoFrame) {
    delete mLastVideoFrame;
    mLastVideoFrame = NULL;
  }
  if (mPlugin) {
    GetMediaPluginHost()->DestroyDecoder(mPlugin);
    mPlugin = NULL;
  }

  return NS_OK;
}
示例#6
0
/* static */
MediaDecoderReader* DecoderTraits::CreateReader(const nsACString& aType, AbstractMediaDecoder* aDecoder)
{
  MediaDecoderReader* decoderReader = nullptr;

#ifdef MOZ_GSTREAMER
  if (IsGStreamerSupportedType(aType)) {
    decoderReader = new GStreamerReader(aDecoder);
  } else
#endif
#ifdef MOZ_RAW
  if (IsRawType(aType)) {
    decoderReader = new RawReader(aDecoder);
  } else
#endif
#ifdef MOZ_OGG
  if (IsOggType(aType)) {
    decoderReader = new OggReader(aDecoder);
  } else
#endif
#ifdef MOZ_WAVE
  if (IsWaveType(aType)) {
    decoderReader = new WaveReader(aDecoder);
  } else
#endif
#ifdef MOZ_OMX_DECODER
  if (IsOmxSupportedType(aType)) {
    decoderReader = new MediaOmxReader(aDecoder);
  } else
#endif
#ifdef MOZ_MEDIA_PLUGINS
  if (MediaDecoder::IsMediaPluginsEnabled() &&
      GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
    decoderReader = new MediaPluginReader(aDecoder, aType);
  } else
#endif
#ifdef MOZ_WEBM
  if (IsWebMType(aType)) {
    decoderReader = new WebMReader(aDecoder);
  } else
#endif
#ifdef MOZ_DIRECTSHOW
  // Note: DirectShowReader is preferred for MP3, but if it's disabled we
  // fallback to the WMFReader.
  if (IsDirectShowSupportedType(aType)) {
    decoderReader = new DirectShowReader(aDecoder);
  } else
#endif
#ifdef MOZ_WMF
  if (IsWMFSupportedType(aType)) {
    decoderReader = new WMFReader(aDecoder);
  } else
#endif
#ifdef MOZ_APPLEMEDIA
  if (IsAppleMediaSupportedType(aType)) {
    decoderReader = new AppleMP3Reader(aDecoder);
  } else
#endif
#ifdef MOZ_DASH
  // The DASH decoder is not supported.
#endif
  if (false) {} // dummy if to take care of the dangling else

  return decoderReader;
}
示例#7
0
/* static */
already_AddRefed<MediaDecoder>
DecoderTraits::CreateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
{
  nsRefPtr<MediaDecoder> decoder;

#ifdef MOZ_GSTREAMER
  if (IsGStreamerSupportedType(aType)) {
    decoder = new GStreamerDecoder();
  }
#endif
#ifdef MOZ_RAW
  if (IsRawType(aType)) {
    decoder = new RawDecoder();
  }
#endif
#ifdef MOZ_OGG
  if (IsOggType(aType)) {
    decoder = new OggDecoder();
  }
#endif
#ifdef MOZ_WAVE
  if (IsWaveType(aType)) {
    decoder = new WaveDecoder();
  }
#endif
#ifdef MOZ_OMX_DECODER
  if (IsOmxSupportedType(aType)) {
    // AMR audio is enabled for MMS, but we are discouraging Web and App
    // developers from using AMR, thus we only allow AMR to be played on WebApps.
    if (aType.EqualsASCII("audio/amr")) {
      HTMLMediaElement* element = aOwner->GetMediaElement();
      if (!element) {
        return nullptr;
      }
      nsIPrincipal* principal = element->NodePrincipal();
      if (!principal) {
        return nullptr;
      }
      if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
        return nullptr;
      }
    }
    decoder = new MediaOmxDecoder();
  }
#endif
#ifdef MOZ_MEDIA_PLUGINS
  if (MediaDecoder::IsMediaPluginsEnabled() && GetMediaPluginHost()->FindDecoder(aType, NULL)) {
    decoder = new MediaPluginDecoder(aType);
  }
#endif
#ifdef MOZ_WEBM
  if (IsWebMType(aType)) {
    decoder = new WebMDecoder();
  }
#endif
#ifdef MOZ_DASH
  if (IsDASHMPDType(aType)) {
    decoder = new DASHDecoder();
  }
#endif
#ifdef MOZ_DIRECTSHOW
  // Note: DirectShow decoder must come before WMFDecoder, else the pref
  // "media.directshow.preferred" won't be honored.
  if (IsDirectShowSupportedType(aType)) {
    decoder = new DirectShowDecoder();
  }
#endif
#ifdef MOZ_WMF
  if (IsWMFSupportedType(aType)) {
    decoder = new WMFDecoder();
  }
#endif
#ifdef MOZ_APPLEMEDIA
  if (IsAppleMediaSupportedType(aType)) {
    decoder = new AppleDecoder();
  }
#endif

  NS_ENSURE_TRUE(decoder != nullptr, nullptr);
  NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);

  return decoder.forget();
}
示例#8
0
/* static */
CanPlayStatus
DecoderTraits::CanHandleMediaType(const char* aMIMEType,
                                  bool aHaveRequestedCodecs,
                                  const nsAString& aRequestedCodecs)
{
  char const* const* codecList = nullptr;
  CanPlayStatus result = CANPLAY_NO;
#ifdef MOZ_RAW
  if (IsRawType(nsDependentCString(aMIMEType))) {
    codecList = gRawCodecs;
    result = CANPLAY_MAYBE;
  }
#endif
#ifdef MOZ_OGG
  if (IsOggType(nsDependentCString(aMIMEType))) {
    codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
    result = CANPLAY_MAYBE;
  }
#endif
#ifdef MOZ_WAVE
  if (IsWaveType(nsDependentCString(aMIMEType))) {
    codecList = gWaveCodecs;
    result = CANPLAY_MAYBE;
  }
#endif
#ifdef MOZ_WEBM
  if (IsWebMType(nsDependentCString(aMIMEType))) {
    codecList = gWebMCodecs;
    result = CANPLAY_YES;
  }
#endif
#ifdef MOZ_DASH
  if (IsDASHMPDType(nsDependentCString(aMIMEType))) {
    // DASH manifest uses WebM codecs only.
    codecList = gWebMCodecs;
    result = CANPLAY_YES;
  }
#endif
#ifdef MOZ_GSTREAMER
  if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType),
                                           aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) {
    if (aHaveRequestedCodecs)
      return CANPLAY_YES;
    return CANPLAY_MAYBE;
  }
#endif
#ifdef MOZ_OMX_DECODER
  if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
    result = CANPLAY_MAYBE;
    if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
      codecList = gMpegAudioCodecs;
    } else {
      codecList = gH264Codecs;
    }
  }
#endif
#ifdef MOZ_WMF
  if (WMFDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) {
    result = CANPLAY_MAYBE;
  }
#endif
#ifdef MOZ_DIRECTSHOW
  if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) {
    result = CANPLAY_MAYBE;
  }
#endif
#ifdef MOZ_APPLEMEDIA
  if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList)) {
    result = CANPLAY_MAYBE;
  }
#endif
#ifdef MOZ_MEDIA_PLUGINS
  if (MediaDecoder::IsMediaPluginsEnabled() &&
      GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList))
    result = CANPLAY_MAYBE;
#endif
  if (result == CANPLAY_NO || !aHaveRequestedCodecs || !codecList) {
    return result;
  }

  // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
  // of the 'codecs' parameter
  nsCharSeparatedTokenizer tokenizer(aRequestedCodecs, ',');
  bool expectMoreTokens = false;
  while (tokenizer.hasMoreTokens()) {
    const nsSubstring& token = tokenizer.nextToken();

    if (!CodecListContains(codecList, token)) {
      // Totally unsupported codec
      return CANPLAY_NO;
    }
    expectMoreTokens = tokenizer.lastTokenEndedWithSeparator();
  }
  if (expectMoreTokens) {
    // Last codec name was empty
    return CANPLAY_NO;
  }
  return CANPLAY_YES;
}
示例#9
0
// Instantiates but does not initialize decoder.
static
already_AddRefed<MediaDecoder>
InstantiateDecoder(const nsACString& aType, MediaDecoderOwner* aOwner)
{
    nsRefPtr<MediaDecoder> decoder;

#ifdef MOZ_FMP4
    if (IsMP4SupportedType(aType)) {
        decoder = new MP4Decoder();
        return decoder.forget();
    }
#endif
#ifdef MOZ_GSTREAMER
    if (IsGStreamerSupportedType(aType)) {
        decoder = new GStreamerDecoder();
        return decoder.forget();
    }
#endif
#ifdef MOZ_RAW
    if (IsRawType(aType)) {
        decoder = new RawDecoder();
        return decoder.forget();
    }
#endif
    if (IsOggType(aType)) {
        decoder = new OggDecoder();
        return decoder.forget();
    }
#ifdef MOZ_WAVE
    if (IsWaveType(aType)) {
        decoder = new WaveDecoder();
        return decoder.forget();
    }
#endif
#ifdef MOZ_OMX_DECODER
    if (IsOmxSupportedType(aType)) {
        // AMR audio is enabled for MMS, but we are discouraging Web and App
        // developers from using AMR, thus we only allow AMR to be played on WebApps.
        if (aType.EqualsASCII("audio/amr")) {
            dom::HTMLMediaElement* element = aOwner->GetMediaElement();
            if (!element) {
                return nullptr;
            }
            nsIPrincipal* principal = element->NodePrincipal();
            if (!principal) {
                return nullptr;
            }
            if (principal->GetAppStatus() < nsIPrincipal::APP_STATUS_PRIVILEGED) {
                return nullptr;
            }
        }
        decoder = new MediaOmxDecoder();
        return decoder.forget();
    }
#endif
#ifdef NECKO_PROTOCOL_rtsp
    if (IsRtspSupportedType(aType)) {
        decoder = new RtspOmxDecoder();
        return decoder.forget();
    }
#endif
#ifdef MOZ_MEDIA_PLUGINS
    if (MediaDecoder::IsMediaPluginsEnabled() &&
            GetMediaPluginHost()->FindDecoder(aType, nullptr)) {
        decoder = new MediaPluginDecoder(aType);
        return decoder.forget();
    }
#endif
#ifdef MOZ_WEBM
    if (IsWebMType(aType)) {
        decoder = new WebMDecoder();
        return decoder.forget();
    }
#endif
#ifdef MOZ_DIRECTSHOW
    // Note: DirectShow should come before WMF, so that we prefer DirectShow's
    // MP3 support over WMF's.
    if (IsDirectShowSupportedType(aType)) {
        decoder = new DirectShowDecoder();
        return decoder.forget();
    }
#endif
#ifdef MOZ_WMF
    if (IsWMFSupportedType(aType)) {
        decoder = new WMFDecoder();
        return decoder.forget();
    }
#endif
#ifdef MOZ_APPLEMEDIA
    if (IsAppleMediaSupportedType(aType)) {
        decoder = new AppleDecoder();
        return decoder.forget();
    }
#endif

    NS_ENSURE_TRUE(decoder != nullptr, nullptr);
    NS_ENSURE_TRUE(decoder->Init(aOwner), nullptr);
    return nullptr;
}
示例#10
0
/* static */
CanPlayStatus
DecoderTraits::CanHandleMediaType(const char* aMIMEType,
                                  bool aHaveRequestedCodecs,
                                  const nsAString& aRequestedCodecs)
{
    char const* const* codecList = nullptr;
    CanPlayStatus result = CANPLAY_NO;
#ifdef MOZ_RAW
    if (IsRawType(nsDependentCString(aMIMEType))) {
        codecList = gRawCodecs;
        result = CANPLAY_MAYBE;
    }
#endif
    if (IsOggType(nsDependentCString(aMIMEType))) {
        codecList = MediaDecoder::IsOpusEnabled() ? gOggCodecsWithOpus : gOggCodecs;
        result = CANPLAY_MAYBE;
    }
#ifdef MOZ_WAVE
    if (IsWaveType(nsDependentCString(aMIMEType))) {
        codecList = gWaveCodecs;
        result = CANPLAY_MAYBE;
    }
#endif
#if defined(MOZ_WEBM) && !defined(MOZ_OMX_WEBM_DECODER)
    if (IsWebMType(nsDependentCString(aMIMEType))) {
        codecList = gWebMCodecs;
        result = CANPLAY_MAYBE;
    }
#endif
#ifdef MOZ_GSTREAMER
    if (GStreamerDecoder::CanHandleMediaType(nsDependentCString(aMIMEType),
            aHaveRequestedCodecs ? &aRequestedCodecs : nullptr)) {
        if (aHaveRequestedCodecs)
            return CANPLAY_YES;
        return CANPLAY_MAYBE;
    }
#endif
#ifdef MOZ_OMX_DECODER
    if (IsOmxSupportedType(nsDependentCString(aMIMEType))) {
        result = CANPLAY_MAYBE;
        if (nsDependentCString(aMIMEType).EqualsASCII("audio/mpeg")) {
            codecList = gMpegAudioCodecs;
#ifdef MOZ_OMX_WEBM_DECODER
        } else if (nsDependentCString(aMIMEType).EqualsASCII("audio/webm") ||
                   nsDependentCString(aMIMEType).EqualsASCII("video/webm")) {
            codecList = gOMXWebMCodecs;
#endif
        } else {
            codecList = gH264Codecs;
        }
    }
#endif
#ifdef MOZ_DIRECTSHOW
    // Note: DirectShow should come before WMF, so that we prefer DirectShow's
    // MP3 support over WMF's.
    if (DirectShowDecoder::GetSupportedCodecs(nsDependentCString(aMIMEType), &codecList)) {
        result = CANPLAY_MAYBE;
    }
#endif
#ifdef MOZ_WMF
    if (IsWMFSupportedType(nsDependentCString(aMIMEType))) {
        if (!aHaveRequestedCodecs) {
            return CANPLAY_MAYBE;
        }
        return WMFDecoder::CanPlayType(nsDependentCString(aMIMEType),
                                       aRequestedCodecs)
               ? CANPLAY_YES : CANPLAY_NO;
    }
#endif
#ifdef MOZ_APPLEMEDIA
    if (IsAppleMediaSupportedType(nsDependentCString(aMIMEType), &codecList)) {
        result = CANPLAY_MAYBE;
    }
#endif
#ifdef MOZ_MEDIA_PLUGINS
    if (MediaDecoder::IsMediaPluginsEnabled() &&
            GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), &codecList))
        result = CANPLAY_MAYBE;
#endif
#ifdef NECKO_PROTOCOL_rtsp
    if (IsRtspSupportedType(nsDependentCString(aMIMEType))) {
        result = CANPLAY_MAYBE;
    }
#endif
    if (result == CANPLAY_NO || !aHaveRequestedCodecs || !codecList) {
        return result;
    }

    // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
    // of the 'codecs' parameter
    nsCharSeparatedTokenizer tokenizer(aRequestedCodecs, ',');
    bool expectMoreTokens = false;
    while (tokenizer.hasMoreTokens()) {
        const nsSubstring& token = tokenizer.nextToken();

        if (!CodecListContains(codecList, token)) {
            // Totally unsupported codec
            return CANPLAY_NO;
        }
        expectMoreTokens = tokenizer.separatorAfterCurrentToken();
    }
    if (expectMoreTokens) {
        // Last codec name was empty
        return CANPLAY_NO;
    }
    return CANPLAY_YES;
}