Home | History | Annotate | Download | only in mediastream
      1 /*
      2  * Copyright (C) 2011 Ericsson AB. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  *
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer
     12  *    in the documentation and/or other materials provided with the
     13  *    distribution.
     14  * 3. Neither the name of Ericsson nor the names of its contributors
     15  *    may be used to endorse or promote products derived from this
     16  *    software without specific prior written permission.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #ifndef UserMediaRequest_h
     32 #define UserMediaRequest_h
     33 
     34 #include "core/dom/ActiveDOMObject.h"
     35 #include "core/platform/mediastream/MediaStreamSource.h"
     36 #include "modules/mediastream/NavigatorUserMediaErrorCallback.h"
     37 #include "modules/mediastream/NavigatorUserMediaSuccessCallback.h"
     38 #include "wtf/PassRefPtr.h"
     39 #include "wtf/RefCounted.h"
     40 #include "wtf/text/WTFString.h"
     41 
     42 namespace WebCore {
     43 
     44 class Dictionary;
     45 class Document;
     46 class ExceptionState;
     47 class MediaConstraints;
     48 class MediaConstraintsImpl;
     49 class MediaStreamDescriptor;
     50 class UserMediaController;
     51 
     52 class UserMediaRequest : public RefCounted<UserMediaRequest>, public ContextLifecycleObserver {
     53 public:
     54     static PassRefPtr<UserMediaRequest> create(ScriptExecutionContext*, UserMediaController*, const Dictionary& options, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>, ExceptionState&);
     55     ~UserMediaRequest();
     56 
     57     NavigatorUserMediaSuccessCallback* successCallback() const { return m_successCallback.get(); }
     58     NavigatorUserMediaErrorCallback* errorCallback() const { return m_errorCallback.get(); }
     59     Document* ownerDocument();
     60 
     61     void start();
     62 
     63     void succeed(PassRefPtr<MediaStreamDescriptor>);
     64     void fail(const String& description);
     65     void failConstraint(const String& constraintName, const String& description);
     66 
     67     bool audio() const;
     68     bool video() const;
     69     MediaConstraints* audioConstraints() const;
     70     MediaConstraints* videoConstraints() const;
     71 
     72     // ContextLifecycleObserver
     73     virtual void contextDestroyed();
     74 
     75 private:
     76     UserMediaRequest(ScriptExecutionContext*, UserMediaController*, PassRefPtr<MediaConstraintsImpl> audio, PassRefPtr<MediaConstraintsImpl> video, PassRefPtr<NavigatorUserMediaSuccessCallback>, PassRefPtr<NavigatorUserMediaErrorCallback>);
     77 
     78     RefPtr<MediaConstraintsImpl> m_audio;
     79     RefPtr<MediaConstraintsImpl> m_video;
     80 
     81     UserMediaController* m_controller;
     82 
     83     RefPtr<NavigatorUserMediaSuccessCallback> m_successCallback;
     84     RefPtr<NavigatorUserMediaErrorCallback> m_errorCallback;
     85 };
     86 
     87 } // namespace WebCore
     88 
     89 #endif // UserMediaRequest_h
     90