Bug 1077159 - Use macros for GMP API names, to make them implicitly versionable. r=jesup
authorChris Pearce <cpearce@mozilla.com>
Wed, 10 Dec 2014 09:35:26 +1300
changeset 218908 817f770bff547fc9c0109d4476ddca867000fd8a
parent 218907 c291b2eac8090c5d6b6f4e02b3f6d479e5450b55
child 218909 38478b0b00fbd37439bed25344b6246303f3759c
push id52675
push usercpearce@mozilla.com
push dateTue, 09 Dec 2014 20:37:23 +0000
treeherdermozilla-inbound@817f770bff54 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup
bugs1077159
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1077159 - Use macros for GMP API names, to make them implicitly versionable. r=jesup
dom/media/eme/MediaKeySystemAccess.cpp
dom/media/gmp-plugin/gmp-fake.cpp
dom/media/gmp/GMPChild.cpp
dom/media/gmp/GMPParent.cpp
dom/media/gmp/GMPService.cpp
dom/media/gmp/gmp-api/gmp-async-shutdown.h
dom/media/gmp/gmp-api/gmp-audio-decode.h
dom/media/gmp/gmp-api/gmp-decryption.h
dom/media/gmp/gmp-api/gmp-entrypoints.h
dom/media/gmp/gmp-api/gmp-video-decode.h
dom/media/gmp/gmp-api/gmp-video-encode.h
media/gmp-clearkey/0.1/gmp-clearkey.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
--- a/dom/media/eme/MediaKeySystemAccess.cpp
+++ b/dom/media/eme/MediaKeySystemAccess.cpp
@@ -97,27 +97,27 @@ MediaKeySystemAccess::IsKeySystemSupport
     do_GetService("@mozilla.org/gecko-media-plugin-service;1");
   if (NS_WARN_IF(!mps)) {
     return false;
   }
 
   if (aKeySystem.EqualsLiteral("org.w3.clearkey") &&
       HaveGMPFor(mps,
                  NS_LITERAL_CSTRING("org.w3.clearkey"),
-                 NS_LITERAL_CSTRING("eme-decrypt"))) {
+                 NS_LITERAL_CSTRING(GMP_API_DECRYPTOR))) {
     return true;
   }
 
 #ifdef XP_WIN
   if (aKeySystem.EqualsLiteral("com.adobe.access") &&
       Preferences::GetBool("media.eme.adobe-access.enabled", false) &&
       IsVistaOrLater() && // Win Vista and later only.
       HaveGMPFor(mps,
                  NS_LITERAL_CSTRING("com.adobe.access"),
-                 NS_LITERAL_CSTRING("eme-decrypt"))) {
+                 NS_LITERAL_CSTRING(GMP_API_DECRYPTOR))) {
       return true;
   }
 #endif
 
   return false;
 }
 
 static bool
@@ -151,21 +151,21 @@ IsPlayableWithGMP(mozIGeckoMediaPluginSe
                                       hasAAC,
                                       hasH264,
                                       hasMP3) ||
       hasMP3) {
     return false;
   }
   return (!hasAAC || !HaveGMPFor(aGMPS,
                                  NS_ConvertUTF16toUTF8(aKeySystem),
-                                 NS_LITERAL_CSTRING("eme-decrypt"),
+                                 NS_LITERAL_CSTRING(GMP_API_DECRYPTOR),
                                  NS_LITERAL_CSTRING("aac"))) &&
          (!hasH264 || !HaveGMPFor(aGMPS,
                                   NS_ConvertUTF16toUTF8(aKeySystem),
-                                  NS_LITERAL_CSTRING("eme-decrypt"),
+                                  NS_LITERAL_CSTRING(GMP_API_DECRYPTOR),
                                   NS_LITERAL_CSTRING("h264")));
 #else
   return false;
 #endif
 }
 
 /* static */
 bool
--- a/dom/media/gmp-plugin/gmp-fake.cpp
+++ b/dom/media/gmp-plugin/gmp-fake.cpp
@@ -390,26 +390,26 @@ extern "C" {
   PUBLIC_FUNC GMPErr
   GMPInit (GMPPlatformAPI* aPlatformAPI) {
     g_platform_api = aPlatformAPI;
     return GMPNoErr;
   }
 
   PUBLIC_FUNC GMPErr
   GMPGetAPI (const char* aApiName, void* aHostAPI, void** aPluginApi) {
-    if (!strcmp (aApiName, "decode-video")) {
+    if (!strcmp (aApiName, GMP_API_VIDEO_DECODER)) {
       *aPluginApi = new FakeVideoDecoder (static_cast<GMPVideoHost*> (aHostAPI));
       return GMPNoErr;
-    } else if (!strcmp (aApiName, "encode-video")) {
+    } else if (!strcmp (aApiName, GMP_API_VIDEO_ENCODER)) {
       *aPluginApi = new FakeVideoEncoder (static_cast<GMPVideoHost*> (aHostAPI));
       return GMPNoErr;
-    } else if (!strcmp (aApiName, "eme-decrypt")) {
+    } else if (!strcmp (aApiName, GMP_API_DECRYPTOR)) {
       *aPluginApi = new FakeDecryptor(static_cast<GMPDecryptorHost*> (aHostAPI));
       return GMPNoErr;
-    } else if (!strcmp (aApiName, "async-shutdown")) {
+    } else if (!strcmp (aApiName, GMP_API_ASYNC_SHUTDOWN)) {
       *aPluginApi = new TestAsyncShutdown(static_cast<GMPAsyncShutdownHost*> (aHostAPI));
       return GMPNoErr;
     }
     return GMPGenericErr;
   }
 
   PUBLIC_FUNC void
   GMPShutdown (void) {
--- a/dom/media/gmp/GMPChild.cpp
+++ b/dom/media/gmp/GMPChild.cpp
@@ -427,17 +427,17 @@ GMPChild::RecvStartPlugin()
                         mNodeId.size(),
                         platformAPI)) {
     NS_WARNING("Failed to load GMP");
     return false;
   }
 
   void* sh = nullptr;
   GMPAsyncShutdownHost* host = static_cast<GMPAsyncShutdownHost*>(this);
-  GMPErr err = GetAPI("async-shutdown", host, &sh);
+  GMPErr err = GetAPI(GMP_API_ASYNC_SHUTDOWN, host, &sh);
   if (err == GMPNoErr && sh) {
     mAsyncShutdown = reinterpret_cast<GMPAsyncShutdown*>(sh);
     SendAsyncShutdownRequired();
   }
 
   return true;
 }
 
@@ -539,17 +539,17 @@ GMPChild::DeallocPGMPDecryptorChild(PGMP
 }
 
 bool
 GMPChild::RecvPGMPAudioDecoderConstructor(PGMPAudioDecoderChild* aActor)
 {
   auto vdc = static_cast<GMPAudioDecoderChild*>(aActor);
 
   void* vd = nullptr;
-  GMPErr err = GetAPI("decode-audio", &vdc->Host(), &vd);
+  GMPErr err = GetAPI(GMP_API_AUDIO_DECODER, &vdc->Host(), &vd);
   if (err != GMPNoErr || !vd) {
     return false;
   }
 
   vdc->Init(static_cast<GMPAudioDecoder*>(vd));
 
   return true;
 }
@@ -568,34 +568,34 @@ GMPChild::DeallocPGMPVideoEncoderChild(P
 }
 
 bool
 GMPChild::RecvPGMPVideoDecoderConstructor(PGMPVideoDecoderChild* aActor)
 {
   auto vdc = static_cast<GMPVideoDecoderChild*>(aActor);
 
   void* vd = nullptr;
-  GMPErr err = GetAPI("decode-video", &vdc->Host(), &vd);
+  GMPErr err = GetAPI(GMP_API_VIDEO_DECODER, &vdc->Host(), &vd);
   if (err != GMPNoErr || !vd) {
     NS_WARNING("GMPGetAPI call failed trying to construct decoder.");
     return false;
   }
 
   vdc->Init(static_cast<GMPVideoDecoder*>(vd));
 
   return true;
 }
 
 bool
 GMPChild::RecvPGMPVideoEncoderConstructor(PGMPVideoEncoderChild* aActor)
 {
   auto vec = static_cast<GMPVideoEncoderChild*>(aActor);
 
   void* ve = nullptr;
-  GMPErr err = GetAPI("encode-video", &vec->Host(), &ve);
+  GMPErr err = GetAPI(GMP_API_VIDEO_ENCODER, &vec->Host(), &ve);
   if (err != GMPNoErr || !ve) {
     NS_WARNING("GMPGetAPI call failed trying to construct encoder.");
     return false;
   }
 
   vec->Init(static_cast<GMPVideoEncoder*>(ve));
 
   return true;
@@ -603,17 +603,17 @@ GMPChild::RecvPGMPVideoEncoderConstructo
 
 bool
 GMPChild::RecvPGMPDecryptorConstructor(PGMPDecryptorChild* aActor)
 {
   GMPDecryptorChild* child = static_cast<GMPDecryptorChild*>(aActor);
   GMPDecryptorHost* host = static_cast<GMPDecryptorHost*>(child);
 
   void* session = nullptr;
-  GMPErr err = GetAPI("eme-decrypt", host, &session);
+  GMPErr err = GetAPI(GMP_API_DECRYPTOR, host, &session);
   if (err != GMPNoErr || !session) {
     return false;
   }
 
   child->Init(static_cast<GMPDecryptor*>(session));
 
   return true;
 }
--- a/dom/media/gmp/GMPParent.cpp
+++ b/dom/media/gmp/GMPParent.cpp
@@ -957,17 +957,17 @@ GMPParent::ReadGMPMetaData()
         while (tagTokens.hasMoreTokens()) {
           const nsDependentCSubstring tag(tagTokens.nextToken());
           cap->mAPITags.AppendElement(tag);
         }
       }
     }
 
 #if defined(XP_LINUX) && defined(MOZ_GMP_SANDBOX)
-    if (cap->mAPIName.EqualsLiteral("eme-decrypt") &&
+    if (cap->mAPIName.EqualsLiteral(GMP_API_DECRYPTOR) &&
         !mozilla::SandboxInfo::Get().CanSandboxMedia()) {
       printf_stderr("GMPParent::ReadGMPMetaData: Plugin \"%s\" is an EME CDM"
                     " but this system can't sandbox it; not loading.\n",
                     mDisplayName.get());
       delete cap;
       return NS_ERROR_FAILURE;
     }
 #endif
--- a/dom/media/gmp/GMPService.cpp
+++ b/dom/media/gmp/GMPService.cpp
@@ -374,17 +374,17 @@ GeckoMediaPluginService::GetGMPAudioDeco
   NS_ENSURE_ARG(aTags && aTags->Length() > 0);
   NS_ENSURE_ARG(aGMPAD);
 
   if (mShuttingDownOnGMPThread) {
     return NS_ERROR_FAILURE;
   }
 
   nsRefPtr<GMPParent> gmp = SelectPluginForAPI(aNodeId,
-                                               NS_LITERAL_CSTRING("decode-audio"),
+                                               NS_LITERAL_CSTRING(GMP_API_AUDIO_DECODER),
                                                *aTags);
   if (!gmp) {
     return NS_ERROR_FAILURE;
   }
 
   GMPAudioDecoderParent* gmpADP;
   nsresult rv = gmp->GetGMPAudioDecoder(&gmpADP);
   if (NS_FAILED(rv)) {
@@ -407,17 +407,17 @@ GeckoMediaPluginService::GetGMPVideoDeco
   NS_ENSURE_ARG(aOutVideoHost);
   NS_ENSURE_ARG(aGMPVD);
 
   if (mShuttingDownOnGMPThread) {
     return NS_ERROR_FAILURE;
   }
 
   nsRefPtr<GMPParent> gmp = SelectPluginForAPI(aNodeId,
-                                               NS_LITERAL_CSTRING("decode-video"),
+                                               NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
                                                *aTags);
 #ifdef PR_LOGGING
   nsCString api = (*aTags)[0];
   LOGD(("%s: %p returning %p for api %s", __FUNCTION__, (void *)this, (void *)gmp, api.get()));
 #endif
   if (!gmp) {
     return NS_ERROR_FAILURE;
   }
@@ -446,17 +446,17 @@ GeckoMediaPluginService::GetGMPVideoEnco
   NS_ENSURE_ARG(aOutVideoHost);
   NS_ENSURE_ARG(aGMPVE);
 
   if (mShuttingDownOnGMPThread) {
     return NS_ERROR_FAILURE;
   }
 
   nsRefPtr<GMPParent> gmp = SelectPluginForAPI(aNodeId,
-                                               NS_LITERAL_CSTRING("encode-video"),
+                                               NS_LITERAL_CSTRING(GMP_API_VIDEO_ENCODER),
                                                *aTags);
 #ifdef PR_LOGGING
   nsCString api = (*aTags)[0];
   LOGD(("%s: %p returning %p for api %s", __FUNCTION__, (void *)this, (void *)gmp, api.get()));
 #endif
   if (!gmp) {
     return NS_ERROR_FAILURE;
   }
@@ -490,17 +490,17 @@ GeckoMediaPluginService::GetGMPDecryptor
   NS_ENSURE_ARG(aTags && aTags->Length() > 0);
   NS_ENSURE_ARG(aDecryptor);
 
   if (mShuttingDownOnGMPThread) {
     return NS_ERROR_FAILURE;
   }
 
   nsRefPtr<GMPParent> gmp = SelectPluginForAPI(aNodeId,
-                                               NS_LITERAL_CSTRING("eme-decrypt"),
+                                               NS_LITERAL_CSTRING(GMP_API_DECRYPTOR),
                                                *aTags);
   if (!gmp) {
     return NS_ERROR_FAILURE;
   }
 
   GMPDecryptorParent* ksp;
   nsresult rv = gmp->GetGMPDecryptor(&ksp);
   if (NS_FAILED(rv)) {
--- a/dom/media/gmp/gmp-api/gmp-async-shutdown.h
+++ b/dom/media/gmp/gmp-api/gmp-async-shutdown.h
@@ -12,33 +12,35 @@
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
 #ifndef GMP_ASYNC_SHUTDOWN_H_
 #define GMP_ASYNC_SHUTDOWN_H_
 
+#define GMP_API_ASYNC_SHUTDOWN "async-shutdown"
+
 // API exposed by the plugin library to manage asynchronous shutdown.
 // Some plugins require special cleanup which may need to make calls
 // to host services and wait for async responses.
 //
 // To enable a plugins to block shutdown until its async shutdown is
 // complete, implement the GMPAsyncShutdown interface and return it when
 // your plugin's GMPGetAPI function is called with "async-shutdown".
 // When your GMPAsyncShutdown's BeginShutdown() implementation is called
 // by the GMP host, you should initate your async shutdown process.
 // Once you have completed shutdown, call the ShutdownComplete() function
 // of the GMPAsyncShutdownHost that is passed as the host argument to the
 // GMPGetAPI() call.
 //
 // Note: Your GMP's GMPShutdown function will still be called after your
 // call to ShutdownComplete().
 //
-// API name: "async-shutdown"
+// API name macro: GMP_API_ASYNC_SHUTDOWN
 // Host API: GMPAsyncShutdownHost
 class GMPAsyncShutdown {
 public:
   virtual ~GMPAsyncShutdown() {}
 
   virtual void BeginShutdown() = 0;
 };
 
--- a/dom/media/gmp/gmp-api/gmp-audio-decode.h
+++ b/dom/media/gmp/gmp-api/gmp-audio-decode.h
@@ -36,16 +36,24 @@ public:
 
   virtual void ResetComplete() = 0;
 
   // Called when the decoder encounters a catestrophic error and cannot
   // continue. Gecko will not send any more input for decoding.
   virtual void Error(GMPErr aError) = 0;
 };
 
+#define GMP_API_AUDIO_DECODER "decode-audio"
+
+// Audio decoding for a single stream. A GMP may be asked to create multiple
+// decoders concurrently.
+//
+// API name macro: GMP_API_AUDIO_DECODER
+// Host API: GMPAudioHost
+//
 // ALL METHODS MUST BE CALLED ON THE MAIN THREAD
 class GMPAudioDecoder
 {
 public:
   virtual ~GMPAudioDecoder() {}
 
   // aCallback: Subclass should retain reference to it until DecodingComplete
   //            is called. Do not attempt to delete it, host retains ownership.
--- a/dom/media/gmp/gmp-api/gmp-decryption.h
+++ b/dom/media/gmp/gmp-api/gmp-decryption.h
@@ -196,20 +196,22 @@ public:
 };
 
 enum GMPSessionType {
   kGMPTemporySession = 0,
   kGMPPersistentSession = 1,
   kGMPSessionInvalid = 2 // Must always be last.
 };
 
+#define GMP_API_DECRYPTOR "eme-decrypt"
+
 // API exposed by plugin library to manage decryption sessions.
 // When the Host requests this by calling GMPGetAPIFunc().
 //
-// API name: "eme-decrypt".
+// API name macro: GMP_API_DECRYPTOR
 // Host API: GMPDecryptorHost
 class GMPDecryptor {
 public:
 
   // Sets the callback to use with the decryptor to return results
   // to Gecko.
   virtual void Init(GMPDecryptorCallback* aCallback) = 0;
 
--- a/dom/media/gmp/gmp-api/gmp-entrypoints.h
+++ b/dom/media/gmp/gmp-api/gmp-entrypoints.h
@@ -44,17 +44,20 @@
 // - Called on main thread.
 // - 'aPlatformAPI' is a structure containing platform-provided APIs. It is valid until
 //   'GMPShutdown' is called. Owned and must be deleted by plugin.
 typedef GMPErr (*GMPInitFunc)(const GMPPlatformAPI* aPlatformAPI);
 
 // GMPGetAPI
 // - Called when host wants to use an API.
 // - Called on main thread.
-// - 'aAPIName' is a string indicating the API being requested.
+// - 'aAPIName' is a string indicating the API being requested. This should
+//   match one of the GMP_API_* macros. Subsequent iterations of the GMP_APIs
+//   may change the value of the GMP_API_* macros when ABI changes occur. So
+//   make sure you compare aAPIName against the corresponding GMP_API_* macro!
 // - 'aHostAPI' is the host API which is specific to the API being requested
 //   from the plugin. It is valid so long as the API object requested from the
 //   plugin is valid. It is owned by the host, plugin should not attempt to delete.
 //   May be null.
 // - 'aPluginAPI' is for returning the requested API. Destruction of the requsted
 //   API object is defined by the API.
 typedef GMPErr (*GMPGetAPIFunc)(const char* aAPIName, void* aHostAPI, void** aPluginAPI);
 
--- a/dom/media/gmp/gmp-api/gmp-video-decode.h
+++ b/dom/media/gmp/gmp-api/gmp-video-decode.h
@@ -58,16 +58,24 @@ public:
 
   virtual void ResetComplete() = 0;
 
   // Called when the decoder encounters a catestrophic error and cannot
   // continue. Gecko will not send any more input for decoding.
   virtual void Error(GMPErr aError) = 0;
 };
 
+#define GMP_API_VIDEO_DECODER "decode-video"
+
+// Video decoding for a single stream. A GMP may be asked to create multiple
+// decoders concurrently.
+//
+// API name macro: GMP_API_VIDEO_DECODER
+// Host API: GMPVideoHost
+//
 // ALL METHODS MUST BE CALLED ON THE MAIN THREAD
 class GMPVideoDecoder
 {
 public:
   virtual ~GMPVideoDecoder() {}
 
   // - aCodecSettings: Details of decoder to create.
   // - aCodecSpecific: codec specific data, cast to a GMPVideoCodecXXX struct
--- a/dom/media/gmp/gmp-api/gmp-video-encode.h
+++ b/dom/media/gmp/gmp-api/gmp-video-encode.h
@@ -52,16 +52,24 @@ public:
                        const uint8_t* aCodecSpecificInfo,
                        uint32_t aCodecSpecificInfoLength) = 0;
 
   // Called when the encoder encounters a catestrophic error and cannot
   // continue. Gecko will not send any more input for encoding.
   virtual void Error(GMPErr aError) = 0;
 };
 
+#define GMP_API_VIDEO_ENCODER "encode-video"
+
+// Video encoding for a single stream. A GMP may be asked to create multiple
+// encoders concurrently.
+//
+// API name macro: GMP_API_VIDEO_ENCODER
+// Host API: GMPVideoHost
+//
 // ALL METHODS MUST BE CALLED ON THE MAIN THREAD
 class GMPVideoEncoder
 {
 public:
   virtual ~GMPVideoEncoder() {}
 
   // Initialize the encoder with the information from the VideoCodec.
   //
--- a/media/gmp-clearkey/0.1/gmp-clearkey.cpp
+++ b/media/gmp-clearkey/0.1/gmp-clearkey.cpp
@@ -26,17 +26,17 @@ GMPInit(GMPPlatformAPI* aPlatformAPI)
 {
   sPlatform = aPlatformAPI;
   return GMPNoErr;
 }
 
 MOZ_EXPORT GMPErr
 GMPGetAPI(const char* aApiName, void* aHostAPI, void** aPluginAPI)
 {
-  if (strcmp(aApiName, "eme-decrypt")) {
+  if (strcmp(aApiName, GMP_API_DECRYPTOR)) {
     return GMPNotImplementedErr;
   }
 
   *aPluginAPI = new ClearKeyDecryptionManager();
 
   return GMPNoErr;
 }
 
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
@@ -20,16 +20,19 @@
 
 #include "nsNetCID.h" // NS_SOCKETTRANSPORTSERVICE_CONTRACTID
 #include "nsServiceManagerUtils.h" // do_GetService
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "mozilla/Services.h"
 #include "StaticPtr.h"
 
+#include "gmp-video-decode.h" // GMP_API_VIDEO_DECODER
+#include "gmp-video-encode.h" // GMP_API_VIDEO_ENCODER
+
 static const char* logTag = "PeerConnectionCtx";
 
 namespace mozilla {
 
 using namespace dom;
 
 class PeerConnectionCtxShutdown : public nsIObserver
 {
@@ -389,24 +392,24 @@ bool PeerConnectionCtx::gmpHasH264() {
 
   // XXX I'd prefer if this was all known ahead of time...
 
   nsTArray<nsCString> tags;
   tags.AppendElement(NS_LITERAL_CSTRING("h264"));
 
   bool has_gmp;
   nsresult rv;
-  rv = mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING("encode-video"),
+  rv = mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING(GMP_API_VIDEO_ENCODER),
                                     &tags,
                                     &has_gmp);
   if (NS_FAILED(rv) || !has_gmp) {
     return false;
   }
 
-  rv = mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING("decode-video"),
+  rv = mGMPService->HasPluginForAPI(NS_LITERAL_CSTRING(GMP_API_VIDEO_DECODER),
                                     &tags,
                                     &has_gmp);
   if (NS_FAILED(rv) || !has_gmp) {
     return false;
   }
 
   return true;
 }