/src/mozilla-central/dom/media/imagecapture/CaptureTask.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim:set ts=2 sw=2 sts=2 et cindent: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef CAPTURETASK_H |
8 | | #define CAPTURETASK_H |
9 | | |
10 | | #include "MediaStreamGraph.h" |
11 | | #include "MediaStreamListener.h" |
12 | | #include "PrincipalChangeObserver.h" |
13 | | #include "MediaStreamVideoSink.h" |
14 | | |
15 | | namespace mozilla { |
16 | | |
17 | | namespace dom { |
18 | | class Blob; |
19 | | class ImageCapture; |
20 | | class MediaStreamTrack; |
21 | | } // namespace dom |
22 | | |
23 | | /** |
24 | | * CaptureTask retrieves image from MediaStream and encodes the image to jpeg in |
25 | | * ImageEncoder. The whole procedures start at AttachTrack(), it will add this |
26 | | * class into MediaStream and retrieves an image in MediaStreamGraph thread. |
27 | | * Once the image is retrieved, it will be sent to ImageEncoder and the encoded |
28 | | * blob will be sent out via encoder callback in main thread. |
29 | | * |
30 | | * CaptureTask holds a reference of ImageCapture to ensure ImageCapture won't be |
31 | | * released during the period of the capturing process described above. |
32 | | */ |
33 | | class CaptureTask : public MediaStreamVideoSink, |
34 | | public dom::PrincipalChangeObserver<dom::MediaStreamTrack> |
35 | | { |
36 | | public: |
37 | | class MediaStreamEventListener; |
38 | | |
39 | | // MediaStreamVideoSink methods. |
40 | | void SetCurrentFrames(const VideoSegment& aSegment) override; |
41 | 0 | void ClearFrames() override {} |
42 | | |
43 | | // PrincipalChangeObserver<MediaStreamTrack> method. |
44 | | void PrincipalChanged(dom::MediaStreamTrack* aMediaStreamTrack) override; |
45 | | |
46 | | // CaptureTask methods. |
47 | | |
48 | | // It is called when aBlob is ready to post back to script in company with |
49 | | // aRv == NS_OK. If aRv is not NS_OK, it will post an error event to script. |
50 | | // |
51 | | // Note: |
52 | | // this function should be called on main thread. |
53 | | nsresult TaskComplete(already_AddRefed<dom::Blob> aBlob, nsresult aRv); |
54 | | |
55 | | // Add listeners into MediaStreamTrack and PrincipalChangeObserver. |
56 | | // It should be on main thread only. |
57 | | void AttachTrack(); |
58 | | |
59 | | // Remove listeners from MediaStreamTrack and PrincipalChangeObserver. |
60 | | // It should be on main thread only. |
61 | | void DetachTrack(); |
62 | | |
63 | | // CaptureTask should be created on main thread. |
64 | | explicit CaptureTask(dom::ImageCapture* aImageCapture); |
65 | | |
66 | | protected: |
67 | 0 | virtual ~CaptureTask() {} |
68 | | |
69 | | // Post a runnable on main thread to end this task and call TaskComplete to post |
70 | | // error event to script. It is called off-main-thread. |
71 | | void PostTrackEndEvent(); |
72 | | |
73 | | // The ImageCapture associates with this task. This reference count should not |
74 | | // change in this class unless it clears this reference after a blob or error |
75 | | // event to script. |
76 | | RefPtr<dom::ImageCapture> mImageCapture; |
77 | | |
78 | | RefPtr<MediaStreamEventListener> mEventListener; |
79 | | |
80 | | // True when an image is retrieved from MediaStreamGraph or MediaStreamGraph |
81 | | // sends a track finish, end, or removed event. |
82 | | bool mImageGrabbedOrTrackEnd; |
83 | | |
84 | | // True after MediaStreamTrack principal changes while waiting for a photo |
85 | | // to finish and we should raise a security error. |
86 | | bool mPrincipalChanged; |
87 | | }; |
88 | | |
89 | | } // namespace mozilla |
90 | | |
91 | | #endif // CAPTURETASK_H |