mozilla-gstreamer-760140.patch
changeset 529 4812378b5646
child 541 830e50bbfc79
equal deleted inserted replaced
528:df6058e8f2a2 529:4812378b5646
       
     1 From: Alessandro Decina <alessandro.d@gmail.com>
       
     2 Bug 760140 - Query the GstRegistry for the required demuxers/decoders from canPlayType
       
     3 
       
     4 diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp
       
     5 --- a/content/base/src/nsContentUtils.cpp
       
     6 +++ b/content/base/src/nsContentUtils.cpp
       
     7 @@ -137,16 +137,19 @@ static NS_DEFINE_CID(kXTFServiceCID, NS_
       
     8  #include "xpcprivate.h" // nsXPConnect
       
     9  #include "nsScriptSecurityManager.h"
       
    10  #include "nsIChannelPolicy.h"
       
    11  #include "nsChannelPolicy.h"
       
    12  #include "nsIContentSecurityPolicy.h"
       
    13  #include "nsContentDLF.h"
       
    14  #ifdef MOZ_MEDIA
       
    15  #include "nsHTMLMediaElement.h"
       
    16 +#ifdef MOZ_GSTREAMER
       
    17 +#include "nsGStreamerDecoder.h"
       
    18 +#endif
       
    19  #endif
       
    20  #include "nsDOMTouchEvent.h"
       
    21  #include "nsIContentViewer.h"
       
    22  #include "nsIObjectLoadingContent.h"
       
    23  #include "nsCCUncollectableMarker.h"
       
    24  #include "mozilla/Base64.h"
       
    25  #include "mozilla/Preferences.h"
       
    26  #include "nsDOMMutationObserver.h"
       
    27 @@ -6511,26 +6514,23 @@ nsContentUtils::FindInternalContentViewe
       
    28          }
       
    29          return docFactory.forget();
       
    30        }
       
    31      }
       
    32    }
       
    33  #endif
       
    34  
       
    35  #ifdef MOZ_GSTREAMER
       
    36 -  if (nsHTMLMediaElement::IsH264Enabled()) {
       
    37 -    for (unsigned int i = 0; i < ArrayLength(nsHTMLMediaElement::gH264Types); ++i) {
       
    38 -      const char* type = nsHTMLMediaElement::gH264Types[i];
       
    39 -      if (!strcmp(aType, type)) {
       
    40 -        docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
       
    41 -        if (docFactory && aLoaderType) {
       
    42 -          *aLoaderType = TYPE_CONTENT;
       
    43 -        }
       
    44 -        return docFactory.forget();
       
    45 +  if (nsHTMLMediaElement::IsGStreamerEnabled()) {
       
    46 +    if (nsGStreamerDecoder::CanHandleMediaType(aType, NULL)) {
       
    47 +      docFactory = do_GetService("@mozilla.org/content/document-loader-factory;1");
       
    48 +      if (docFactory && aLoaderType) {
       
    49 +        *aLoaderType = TYPE_CONTENT;
       
    50        }
       
    51 +      return docFactory.forget();
       
    52      }
       
    53    }
       
    54  #endif
       
    55  #endif // MOZ_MEDIA
       
    56  
       
    57    return NULL;
       
    58  }
       
    59  
       
    60 diff --git a/content/html/content/public/nsHTMLMediaElement.h b/content/html/content/public/nsHTMLMediaElement.h
       
    61 --- a/content/html/content/public/nsHTMLMediaElement.h
       
    62 +++ b/content/html/content/public/nsHTMLMediaElement.h
       
    63 @@ -250,17 +250,19 @@ public:
       
    64    void UpdateMediaSize(nsIntSize size);
       
    65  
       
    66    // Returns the CanPlayStatus indicating if we can handle this
       
    67    // MIME type. The MIME type should not include the codecs parameter.
       
    68    // If it returns anything other than CANPLAY_NO then it also
       
    69    // returns a null-terminated list of supported codecs
       
    70    // in *aSupportedCodecs. This list should not be freed, it is static data.
       
    71    static CanPlayStatus CanHandleMediaType(const char* aMIMEType,
       
    72 -                                          char const *const ** aSupportedCodecs);
       
    73 +                                          const char* aCodecs,
       
    74 +                                          char const *const ** aSupportedCodecs,
       
    75 +                                          bool* aCheckSupportedCodecs);
       
    76  
       
    77    // Returns the CanPlayStatus indicating if we can handle the
       
    78    // full MIME type including the optional codecs parameter.
       
    79    static CanPlayStatus GetCanPlay(const nsAString& aType);
       
    80  
       
    81    // Returns true if we should handle this MIME type when it appears
       
    82    // as an <object> or as a toplevel page. If, in practice, our support
       
    83    // for the type is more limited than appears in the wild, we should return
       
    84 @@ -290,20 +292,17 @@ public:
       
    85  #ifdef MOZ_WEBM
       
    86    static bool IsWebMEnabled();
       
    87    static bool IsWebMType(const nsACString& aType);
       
    88    static const char gWebMTypes[2][17];
       
    89    static char const *const gWebMCodecs[4];
       
    90  #endif
       
    91  
       
    92  #ifdef MOZ_GSTREAMER
       
    93 -  static bool IsH264Enabled();
       
    94 -  static bool IsH264Type(const nsACString& aType);
       
    95 -  static const char gH264Types[3][17];
       
    96 -  static char const *const gH264Codecs[7];
       
    97 +  static bool IsGStreamerEnabled();
       
    98  #endif
       
    99  
       
   100  #ifdef MOZ_MEDIA_PLUGINS
       
   101    static bool IsMediaPluginsEnabled();
       
   102    static bool IsMediaPluginsType(const nsACString& aType);
       
   103  #endif
       
   104  
       
   105    /**
       
   106 diff --git a/content/html/content/src/nsHTMLMediaElement.cpp b/content/html/content/src/nsHTMLMediaElement.cpp
       
   107 --- a/content/html/content/src/nsHTMLMediaElement.cpp
       
   108 +++ b/content/html/content/src/nsHTMLMediaElement.cpp
       
   109 @@ -2070,68 +2070,40 @@ nsHTMLMediaElement::IsWebMType(const nsA
       
   110      }
       
   111    }
       
   112  
       
   113    return false;
       
   114  }
       
   115  #endif
       
   116  
       
   117  #ifdef MOZ_GSTREAMER
       
   118 -const char nsHTMLMediaElement::gH264Types[3][17] = {
       
   119 -  "video/mp4",
       
   120 -  "video/3gpp",
       
   121 -  "video/quicktime",
       
   122 -};
       
   123 -
       
   124 -char const *const nsHTMLMediaElement::gH264Codecs[7] = {
       
   125 -  "avc1.42E01E",
       
   126 -  "avc1.42001E",
       
   127 -  "avc1.58A01E",
       
   128 -  "avc1.4D401E",
       
   129 -  "avc1.64001E",
       
   130 -  "mp4a.40.2",
       
   131 -  nsnull
       
   132 -};
       
   133 -
       
   134  bool
       
   135 -nsHTMLMediaElement::IsH264Enabled()
       
   136 +nsHTMLMediaElement::IsGStreamerEnabled()
       
   137  {
       
   138 -  return Preferences::GetBool("media.h264.enabled");
       
   139 -}
       
   140 -
       
   141 -bool
       
   142 -nsHTMLMediaElement::IsH264Type(const nsACString& aType)
       
   143 -{
       
   144 -  if (!IsH264Enabled()) {
       
   145 -    return false;
       
   146 -  }
       
   147 -
       
   148 -  for (PRUint32 i = 0; i < ArrayLength(gH264Types); ++i) {
       
   149 -    if (aType.EqualsASCII(gH264Types[i])) {
       
   150 -      return true;
       
   151 -    }
       
   152 -  }
       
   153 -
       
   154 -  return false;
       
   155 +  return Preferences::GetBool("media.gstreamer.enabled");
       
   156  }
       
   157  #endif
       
   158  
       
   159  #ifdef MOZ_MEDIA_PLUGINS
       
   160  bool
       
   161  nsHTMLMediaElement::IsMediaPluginsEnabled()
       
   162  {
       
   163    return Preferences::GetBool("media.plugins.enabled");
       
   164  }
       
   165  #endif
       
   166  
       
   167  /* static */
       
   168  nsHTMLMediaElement::CanPlayStatus 
       
   169  nsHTMLMediaElement::CanHandleMediaType(const char* aMIMEType,
       
   170 -                                       char const *const ** aCodecList)
       
   171 +                                       const char *aCodecs,
       
   172 +                                       char const *const ** aCodecList,
       
   173 +                                       bool* aCheckCodecList)
       
   174  {
       
   175 +  if (aCheckCodecList)
       
   176 +    *aCheckCodecList = true;
       
   177  #ifdef MOZ_RAW
       
   178    if (IsRawType(nsDependentCString(aMIMEType))) {
       
   179      *aCodecList = gRawCodecs;
       
   180      return CANPLAY_MAYBE;
       
   181    }
       
   182  #endif
       
   183  #ifdef MOZ_OGG
       
   184    if (IsOggType(nsDependentCString(aMIMEType))) {
       
   185 @@ -2148,20 +2120,22 @@ nsHTMLMediaElement::CanHandleMediaType(c
       
   186  #ifdef MOZ_WEBM
       
   187    if (IsWebMType(nsDependentCString(aMIMEType))) {
       
   188      *aCodecList = gWebMCodecs;
       
   189      return CANPLAY_YES;
       
   190    }
       
   191  #endif
       
   192  
       
   193  #ifdef MOZ_GSTREAMER
       
   194 -  if (IsH264Type(nsDependentCString(aMIMEType))) {
       
   195 -    *aCodecList = gH264Codecs;
       
   196 -    return CANPLAY_MAYBE;
       
   197 -  }
       
   198 +  if (aCheckCodecList)
       
   199 +    *aCheckCodecList = false;
       
   200 +  if (aCodecList)
       
   201 +    *aCodecList = NULL;
       
   202 +  if (nsGStreamerDecoder::CanHandleMediaType(aMIMEType, aCodecs))
       
   203 +    return CANPLAY_YES;
       
   204  #endif
       
   205  #ifdef MOZ_MEDIA_PLUGINS
       
   206    if (GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), aCodecList))
       
   207      return CANPLAY_MAYBE;
       
   208  #endif
       
   209    return CANPLAY_NO;
       
   210  }
       
   211  
       
   212 @@ -2176,17 +2150,17 @@ bool nsHTMLMediaElement::ShouldHandleMed
       
   213    if (IsOggType(nsDependentCString(aMIMEType)))
       
   214      return true;
       
   215  #endif
       
   216  #ifdef MOZ_WEBM
       
   217    if (IsWebMType(nsDependentCString(aMIMEType)))
       
   218      return true;
       
   219  #endif
       
   220  #ifdef MOZ_GSTREAMER
       
   221 -  if (IsH264Type(nsDependentCString(aMIMEType)))
       
   222 +  if (nsGStreamerDecoder::CanHandleMediaType(aMIMEType, NULL))
       
   223      return true;
       
   224  #endif
       
   225  #ifdef MOZ_MEDIA_PLUGINS
       
   226    if (GetMediaPluginHost()->FindDecoder(nsDependentCString(aMIMEType), NULL))
       
   227      return true;
       
   228  #endif
       
   229    // We should not return true for Wave types, since there are some
       
   230    // Wave codecs actually in use in the wild that we don't support, and
       
   231 @@ -2212,26 +2186,31 @@ nsHTMLMediaElement::GetCanPlay(const nsA
       
   232  {
       
   233    nsContentTypeParser parser(aType);
       
   234    nsAutoString mimeType;
       
   235    nsresult rv = parser.GetType(mimeType);
       
   236    if (NS_FAILED(rv))
       
   237      return CANPLAY_NO;
       
   238  
       
   239    NS_ConvertUTF16toUTF8 mimeTypeUTF8(mimeType);
       
   240 +  nsAutoString codecs;
       
   241 +  rv = parser.GetParameter("codecs", codecs);
       
   242 +  NS_ConvertUTF16toUTF8 codecsUTF8(codecs);
       
   243    char const *const * supportedCodecs;
       
   244 +  bool checkSupportedCodecs = true;
       
   245    CanPlayStatus status = CanHandleMediaType(mimeTypeUTF8.get(),
       
   246 -                                            &supportedCodecs);
       
   247 +                                            codecsUTF8.get(),
       
   248 +                                            &supportedCodecs,
       
   249 +                                            &checkSupportedCodecs);
       
   250    if (status == CANPLAY_NO)
       
   251      return CANPLAY_NO;
       
   252  
       
   253 -  nsAutoString codecs;
       
   254 -  rv = parser.GetParameter("codecs", codecs);
       
   255 -  if (NS_FAILED(rv)) {
       
   256 -    // Parameter not found or whatever
       
   257 +  if (codecs.IsEmpty() || !checkSupportedCodecs) {
       
   258 +    /* no codecs to check for or they were already checked in CanHandleMediaType
       
   259 +     * above */
       
   260      return status;
       
   261    }
       
   262  
       
   263    CanPlayStatus result = CANPLAY_YES;
       
   264    // See http://www.rfc-editor.org/rfc/rfc4281.txt for the description
       
   265    // of the 'codecs' parameter
       
   266    nsCharSeparatedTokenizer tokenizer(codecs, ',');
       
   267    bool expectMoreTokens = false;
       
   268 @@ -2309,17 +2288,19 @@ nsHTMLMediaElement::CreateDecoder(const 
       
   269      nsRefPtr<nsWebMDecoder> decoder = new nsWebMDecoder();
       
   270      if (decoder->Init(this)) {
       
   271        return decoder.forget();
       
   272      }
       
   273    }
       
   274  #endif
       
   275  
       
   276  #ifdef MOZ_GSTREAMER 
       
   277 -  if (IsH264Type(aType)) {
       
   278 +  const char *type;
       
   279 +  NS_CStringGetData(aType, &type, NULL);
       
   280 +  if (nsGStreamerDecoder::CanHandleMediaType(type, NULL)) {
       
   281      nsRefPtr<nsGStreamerDecoder> decoder = new nsGStreamerDecoder();
       
   282      if (decoder->Init(this)) {
       
   283        return decoder.forget();
       
   284      }
       
   285    }
       
   286  #endif
       
   287    return nsnull;
       
   288  }
       
   289 diff --git a/content/media/gstreamer/Makefile.in b/content/media/gstreamer/Makefile.in
       
   290 --- a/content/media/gstreamer/Makefile.in
       
   291 +++ b/content/media/gstreamer/Makefile.in
       
   292 @@ -16,16 +16,17 @@ LIBXUL_LIBRARY 	= 1
       
   293  
       
   294  EXPORTS		+= \
       
   295  		nsGStreamerDecoder.h \
       
   296  		$(NULL)
       
   297  
       
   298  CPPSRCS		= \
       
   299  		nsGStreamerReader.cpp \
       
   300  		nsGStreamerDecoder.cpp \
       
   301 +		nsGStreamerFormatHelper.cpp \
       
   302  		$(NULL)
       
   303  
       
   304  FORCE_STATIC_LIB = 1
       
   305  
       
   306  include $(topsrcdir)/config/rules.mk
       
   307  
       
   308  CFLAGS		+= $(GSTREAMER_CFLAGS)
       
   309  CXXFLAGS	+= $(GSTREAMER_CFLAGS)
       
   310 diff --git a/content/media/gstreamer/nsGStreamerDecoder.cpp b/content/media/gstreamer/nsGStreamerDecoder.cpp
       
   311 --- a/content/media/gstreamer/nsGStreamerDecoder.cpp
       
   312 +++ b/content/media/gstreamer/nsGStreamerDecoder.cpp
       
   313 @@ -2,13 +2,19 @@
       
   314  /* vim:set ts=2 sw=2 sts=2 et cindent: */
       
   315  /* This Source Code Form is subject to the terms of the Mozilla Public
       
   316   * License, v. 2.0. If a copy of the MPL was not distributed with this file,
       
   317   * You can obtain one at http://mozilla.org/MPL/2.0/. */
       
   318  
       
   319  #include "nsBuiltinDecoderStateMachine.h"
       
   320  #include "nsGStreamerReader.h"
       
   321  #include "nsGStreamerDecoder.h"
       
   322 +#include "nsGStreamerFormatHelper.h"
       
   323  
       
   324  nsDecoderStateMachine* nsGStreamerDecoder::CreateStateMachine()
       
   325  {
       
   326    return new nsBuiltinDecoderStateMachine(this, new nsGStreamerReader(this));
       
   327  }
       
   328 +
       
   329 +bool nsGStreamerDecoder::CanHandleMediaType(const char* aMIMEType,
       
   330 +                                            const char* aCodecs) {
       
   331 +  return nsGStreamerFormatHelper::Instance()->CanHandleMediaType(aMIMEType, aCodecs);
       
   332 +}
       
   333 diff --git a/content/media/gstreamer/nsGStreamerDecoder.h b/content/media/gstreamer/nsGStreamerDecoder.h
       
   334 --- a/content/media/gstreamer/nsGStreamerDecoder.h
       
   335 +++ b/content/media/gstreamer/nsGStreamerDecoder.h
       
   336 @@ -9,11 +9,12 @@
       
   337  
       
   338  #include "nsBuiltinDecoder.h"
       
   339  
       
   340  class nsGStreamerDecoder : public nsBuiltinDecoder
       
   341  {
       
   342  public:
       
   343    virtual nsMediaDecoder* Clone() { return new nsGStreamerDecoder(); }
       
   344    virtual nsDecoderStateMachine* CreateStateMachine();
       
   345 +  static bool CanHandleMediaType(const char* aMIMEType, const char* aCodecs);
       
   346  };
       
   347  
       
   348  #endif
       
   349 diff --git a/content/media/gstreamer/nsGStreamerFormatHelper.cpp b/content/media/gstreamer/nsGStreamerFormatHelper.cpp
       
   350 new file mode 100644
       
   351 --- /dev/null
       
   352 +++ b/content/media/gstreamer/nsGStreamerFormatHelper.cpp
       
   353 @@ -0,0 +1,149 @@
       
   354 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       
   355 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
       
   356 +/* This Source Code Form is subject to the terms of the Mozilla Public
       
   357 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
       
   358 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
       
   359 +
       
   360 +#include "nsGStreamerFormatHelper.h"
       
   361 +#include "nsCharSeparatedTokenizer.h"
       
   362 +#include "nsXPCOMStrings.h"
       
   363 +
       
   364 +#define ENTRY_FORMAT(entry) entry[0]
       
   365 +#define ENTRY_CAPS(entry) entry[1]
       
   366 +
       
   367 +nsGStreamerFormatHelper* nsGStreamerFormatHelper::gInstance = NULL;
       
   368 +
       
   369 +nsGStreamerFormatHelper *nsGStreamerFormatHelper::Instance() {
       
   370 +  if (!gInstance) {
       
   371 +    gst_init(NULL, NULL);
       
   372 +    gInstance = new nsGStreamerFormatHelper();
       
   373 +  }
       
   374 +
       
   375 +  return gInstance;
       
   376 +}
       
   377 +
       
   378 +nsGStreamerFormatHelper::nsGStreamerFormatHelper()
       
   379 +  : mFactories(NULL),
       
   380 +    mCookie(0)
       
   381 +{
       
   382 +  const char *containers[3][2] = {
       
   383 +    {"video/mp4", "video/quicktime"},
       
   384 +    {"audio/mp4", "audio/mpeg, mpegversion=(int)4"},
       
   385 +    {"audio/mpeg", "audio/mpeg, mpegversion=(int)1"},
       
   386 +  };
       
   387 +  memcpy(mContainers, containers, sizeof(containers));
       
   388 +
       
   389 +  const char *codecs[7][2] = {
       
   390 +    {"avc1.42E01E", "video/x-h264"},
       
   391 +    {"avc1.42001E", "video/x-h264"},
       
   392 +    {"avc1.58A01E", "video/x-h264"},
       
   393 +    {"avc1.4D401E", "video/x-h264"},
       
   394 +    {"avc1.64001E", "video/x-h264"},
       
   395 +    {"mp4a.40.2", "audio/mpeg, mpegversion=(int)4"},
       
   396 +    {"mp3", "audio/mpeg, mpegversion=(int)1"},
       
   397 +  };
       
   398 +  memcpy(mCodecs, codecs, sizeof(codecs));
       
   399 +}
       
   400 +
       
   401 +nsGStreamerFormatHelper::~nsGStreamerFormatHelper() {
       
   402 +  if (mFactories)
       
   403 +    g_list_free(mFactories);
       
   404 +}
       
   405 +
       
   406 +bool nsGStreamerFormatHelper::CanHandleMediaType(const char* aMIMEType,
       
   407 +                                                 const char *aCodecs) {
       
   408 +  GstCaps *caps = ConvertFormatsToCaps(aMIMEType, aCodecs);
       
   409 +  if (!caps) {
       
   410 +    return false;
       
   411 +  }
       
   412 +
       
   413 +  bool ret = HaveElementsToProcessCaps(caps);
       
   414 +  gst_caps_unref(caps);
       
   415 +
       
   416 +  return ret;
       
   417 +}
       
   418 +
       
   419 +GstCaps *nsGStreamerFormatHelper::ConvertFormatsToCaps(const char *aMIMEType,
       
   420 +                                                       const char *aCodecs) {
       
   421 +  unsigned int i;
       
   422 +
       
   423 +  /* convert aMIMEType to gst container caps */
       
   424 +  const char *capsString = NULL;
       
   425 +  for (i = 0; i < G_N_ELEMENTS(mContainers); i++) {
       
   426 +    if (!strcmp(ENTRY_FORMAT(mContainers[i]), aMIMEType)) {
       
   427 +      capsString = ENTRY_CAPS(mContainers[i]);
       
   428 +      break;
       
   429 +    }
       
   430 +  }
       
   431 +
       
   432 +  if (!capsString) {
       
   433 +    /* we couldn't find any matching caps */
       
   434 +    return NULL;
       
   435 +  }
       
   436 +
       
   437 +  GstCaps *caps = gst_caps_from_string(capsString);
       
   438 +  /* container only */
       
   439 +  if (!aCodecs) {
       
   440 +    return caps;
       
   441 +  }
       
   442 +
       
   443 +  nsDependentCSubstring codecs(aCodecs, strlen(aCodecs));
       
   444 +  nsCCharSeparatedTokenizer tokenizer(codecs, ',');
       
   445 +  while (tokenizer.hasMoreTokens()) {
       
   446 +    const nsCSubstring& codec = tokenizer.nextToken();
       
   447 +    capsString = NULL;
       
   448 +
       
   449 +    for (i = 0; i < G_N_ELEMENTS(mCodecs); i++) {
       
   450 +      if (codec.Equals(ENTRY_FORMAT(mCodecs[i]))) {
       
   451 +        capsString = ENTRY_CAPS(mCodecs[i]);
       
   452 +        break;
       
   453 +      }
       
   454 +    }
       
   455 +
       
   456 +    if (!capsString) {
       
   457 +      gst_caps_unref(caps);
       
   458 +      return NULL;
       
   459 +    }
       
   460 +
       
   461 +    GstCaps *tmp = gst_caps_from_string(capsString);
       
   462 +    /* appends and frees tmp */
       
   463 +    gst_caps_append(caps, tmp);
       
   464 +  }
       
   465 +
       
   466 +  return caps;
       
   467 +}
       
   468 +
       
   469 +bool nsGStreamerFormatHelper::HaveElementsToProcessCaps(GstCaps *aCaps) {
       
   470 +
       
   471 +  GList *factories = GetFactories();
       
   472 +
       
   473 +  GList *list;
       
   474 +  /* here aCaps contains [containerCaps, [codecCaps1, [codecCaps2, ...]]] so process
       
   475 +   * caps structures individually as we want one element for _each_
       
   476 +   * structure */
       
   477 +  for (unsigned int i = 0; i < gst_caps_get_size(aCaps); i++) {
       
   478 +    GstStructure *s = gst_caps_get_structure(aCaps, i);
       
   479 +    GstCaps *caps = gst_caps_new_full(gst_structure_copy(s), NULL);
       
   480 +    list = gst_element_factory_list_filter (factories, caps, GST_PAD_SINK, FALSE);
       
   481 +    gst_caps_unref(caps);
       
   482 +    if (!list) {
       
   483 +      return false;
       
   484 +    }
       
   485 +    g_list_free(list);
       
   486 +  }
       
   487 +
       
   488 +  return true;
       
   489 +}
       
   490 +
       
   491 +GList * nsGStreamerFormatHelper::GetFactories() {
       
   492 +  uint32_t cookie = gst_default_registry_get_feature_list_cookie ();
       
   493 +  if (cookie != mCookie) {
       
   494 +    g_list_free(mFactories);
       
   495 +    mFactories = gst_element_factory_list_get_elements
       
   496 +        (GST_ELEMENT_FACTORY_TYPE_DEMUXER | GST_ELEMENT_FACTORY_TYPE_DECODER,
       
   497 +         GST_RANK_MARGINAL);
       
   498 +    mCookie = cookie;
       
   499 +  }
       
   500 +
       
   501 +  return mFactories;
       
   502 +}
       
   503 diff --git a/content/media/gstreamer/nsGStreamerFormatHelper.h b/content/media/gstreamer/nsGStreamerFormatHelper.h
       
   504 new file mode 100644
       
   505 --- /dev/null
       
   506 +++ b/content/media/gstreamer/nsGStreamerFormatHelper.h
       
   507 @@ -0,0 +1,37 @@
       
   508 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       
   509 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
       
   510 +/* This Source Code Form is subject to the terms of the Mozilla Public
       
   511 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
       
   512 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
       
   513 +
       
   514 +#if !defined(nsGStreamerFormatHelper_h_)
       
   515 +#define nsGStreamerFormatHelper_h_
       
   516 +
       
   517 +#include <gst/gst.h>
       
   518 +#include <mozilla/Types.h>
       
   519 +
       
   520 +class nsGStreamerFormatHelper {
       
   521 +  public:
       
   522 +    static nsGStreamerFormatHelper *Instance();
       
   523 +    ~nsGStreamerFormatHelper();
       
   524 +
       
   525 +    bool CanHandleMediaType(const char *aMIMEType,
       
   526 +                            const char *aCodecs);
       
   527 +
       
   528 +  private:
       
   529 +    nsGStreamerFormatHelper();
       
   530 +    GstCaps *ConvertFormatsToCaps(const char *aMIMEType,
       
   531 +                                  const char *aCodecs);
       
   532 +    char * const *CodecListFromCaps(GstCaps *aCaps);
       
   533 +    bool HaveElementsToProcessCaps(GstCaps *aCaps);
       
   534 +    GList *GetFactories();
       
   535 +
       
   536 +    static nsGStreamerFormatHelper *gInstance;
       
   537 +
       
   538 +    const char *mContainers[3][2];
       
   539 +    const char *mCodecs[7][2];
       
   540 +    GList *mFactories;
       
   541 +    uint32_t mCookie;
       
   542 +};
       
   543 +
       
   544 +#endif
       
   545 diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js
       
   546 --- a/modules/libpref/src/init/all.js
       
   547 +++ b/modules/libpref/src/init/all.js
       
   548 @@ -159,17 +159,17 @@ pref("media.opus.enabled", true);
       
   549  #endif
       
   550  #ifdef MOZ_WAVE
       
   551  pref("media.wave.enabled", true);
       
   552  #endif
       
   553  #ifdef MOZ_WEBM
       
   554  pref("media.webm.enabled", true);
       
   555  #endif
       
   556  #ifdef MOZ_GSTREAMER
       
   557 -pref("media.h264.enabled", true);
       
   558 +pref("media.gstreamer.enabled", true);
       
   559  #endif
       
   560  
       
   561  
       
   562  // Whether to autostart a media element with an |autoplay| attribute
       
   563  pref("media.autoplay.enabled", true);
       
   564  
       
   565  // 0 = Off, 1 = Full, 2 = Tagged Images Only. 
       
   566  // See eCMSMode in gfx/thebes/gfxPlatform.h