Updates to VCMDecodedFrameCallback, VideoReceiver and a few related classes/tests.

* The _receiveCallback member of VCMDecodedFrameCallback does actually not require locking now that the threading model is slightly clearer. Documentation and checks have been added.
* UserReceiveCallback() never returns null and must always be called on the decoder thread. Checks have been added and the two test suites that were failing to set this callback, have been fixed and a new mock class added.  (looks like sakal@ may have hit some issues with flaky tests there).
* Changed VcmPayloadSink to use move semantics which I suspect was the intention at the time the code was written (when we didn't have move semantics).
* Added thread checker to a couple of classes and started adding thread checks for known behavior.  There's more to be  done there.
* Remove the |_decoder| member variable in VideoReceiver. It is not needed and as it could be used, left us open to a race.
* TODOs added for places where we can reduce locking. I suspect that we can get away with not needing a lock around _codecDataBase in VideoReceiver once we've got a clear picture of the threading model and ensured that all adhere to it.

BUG=webrtc:7328

Review-Url: https://codereview.webrtc.org/2744013002
Cr-Commit-Position: refs/heads/master@{#17226}
diff --git a/webrtc/modules/video_coding/generic_decoder.h b/webrtc/modules/video_coding/generic_decoder.h
index 48e2519..891ec89 100644
--- a/webrtc/modules/video_coding/generic_decoder.h
+++ b/webrtc/modules/video_coding/generic_decoder.h
@@ -11,9 +11,11 @@
 #ifndef WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
 #define WEBRTC_MODULES_VIDEO_CODING_GENERIC_DECODER_H_
 
+#include "webrtc/base/criticalsection.h"
+#include "webrtc/base/thread_checker.h"
 #include "webrtc/modules/include/module_common_types.h"
-#include "webrtc/modules/video_coding/include/video_codec_interface.h"
 #include "webrtc/modules/video_coding/encoded_frame.h"
+#include "webrtc/modules/video_coding/include/video_codec_interface.h"
 #include "webrtc/modules/video_coding/timestamp_map.h"
 #include "webrtc/modules/video_coding/timing.h"
 
@@ -33,32 +35,38 @@
 class VCMDecodedFrameCallback : public DecodedImageCallback {
  public:
   VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
-    virtual ~VCMDecodedFrameCallback();
-    void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
-    VCMReceiveCallback* UserReceiveCallback();
+  ~VCMDecodedFrameCallback() override;
+  void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
+  VCMReceiveCallback* UserReceiveCallback();
 
-    int32_t Decoded(VideoFrame& decodedImage) override;
-    int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override;
-    void Decoded(VideoFrame& decodedImage,
-                 rtc::Optional<int32_t> decode_time_ms,
-                 rtc::Optional<uint8_t> qp) override;
-    int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override;
-    int32_t ReceivedDecodedFrame(const uint64_t pictureId) override;
+  int32_t Decoded(VideoFrame& decodedImage) override;
+  int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms) override;
+  void Decoded(VideoFrame& decodedImage,
+               rtc::Optional<int32_t> decode_time_ms,
+               rtc::Optional<uint8_t> qp) override;
+  int32_t ReceivedDecodedReferenceFrame(const uint64_t pictureId) override;
+  int32_t ReceivedDecodedFrame(const uint64_t pictureId) override;
 
-    uint64_t LastReceivedPictureID() const;
-    void OnDecoderImplementationName(const char* implementation_name);
+  uint64_t LastReceivedPictureID() const;
+  void OnDecoderImplementationName(const char* implementation_name);
 
-    void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
-    int32_t Pop(uint32_t timestamp);
+  void Map(uint32_t timestamp, VCMFrameInformation* frameInfo);
+  int32_t Pop(uint32_t timestamp);
 
  private:
-    // Protect |_receiveCallback| and |_timestampMap|.
-    CriticalSectionWrapper* _critSect;
-    Clock* _clock;
-    VCMReceiveCallback* _receiveCallback GUARDED_BY(_critSect);
-    VCMTiming* _timing;
-    VCMTimestampMap _timestampMap GUARDED_BY(_critSect);
-    uint64_t _lastReceivedPictureID;
+  rtc::ThreadChecker construction_thread_;
+  // Protect |_timestampMap|.
+  Clock* const _clock;
+  // This callback must be set before the decoder thread starts running
+  // and must only be unset when external threads (e.g decoder thread)
+  // have been stopped. Due to that, the variable should regarded as const
+  // while there are more than one threads involved, it must be set
+  // from the same thread, and therfore a lock is not required to access it.
+  VCMReceiveCallback* _receiveCallback = nullptr;
+  VCMTiming* _timing;
+  rtc::CriticalSection lock_;
+  VCMTimestampMap _timestampMap GUARDED_BY(lock_);
+  uint64_t _lastReceivedPictureID;
 };
 
 class VCMGenericDecoder {