VCMGenericDecoder threading updates for all but Android.

* All methods now have thread checks.
* Variable access associated with thread checkers.
* Remove need for |rtc::CriticalSection lock_|

Since the android decoder is inherently asynchronous, and
FrameBuffer2's decoder doesn't support posting tasks to it
yet (for async decode completion), we need to tackle android
separately. Once FrameBuffer2 gets changed to use a TaskQueue
or ProcessThread, we can move Android over to delivering decoded
frames on the right thread/queue and delete generic_decoder_android.*.

Note: This is a subset of code that was previously reviewed here:
  - https://codereview.webrtc.org/2764573002/

Bug: webrtc:7361, webrtc:8907, chromium:695438
Change-Id: I118609dfa5c0f0180287d8c2b6d62987b7473c5c
Reviewed-on: https://webrtc-review.googlesource.com/55060
Commit-Queue: Tommi <tommi@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#22119}
diff --git a/modules/video_coding/generic_decoder.h b/modules/video_coding/generic_decoder.h
index 2d940d8..210a63b 100644
--- a/modules/video_coding/generic_decoder.h
+++ b/modules/video_coding/generic_decoder.h
@@ -18,9 +18,11 @@
 #include "modules/video_coding/include/video_codec_interface.h"
 #include "modules/video_coding/timestamp_map.h"
 #include "modules/video_coding/timing.h"
-#include "rtc_base/criticalsection.h"
 #include "rtc_base/thread_checker.h"
 
+#if defined(WEBRTC_ANDROID)
+#include "modules/video_coding/generic_decoder_android.h"  // NOLINT
+#else
 namespace webrtc {
 
 class VCMReceiveCallback;
@@ -40,6 +42,7 @@
  public:
   VCMDecodedFrameCallback(VCMTiming* timing, Clock* clock);
   ~VCMDecodedFrameCallback() override;
+
   void SetUserReceiveCallback(VCMReceiveCallback* receiveCallback);
   VCMReceiveCallback* UserReceiveCallback();
 
@@ -59,7 +62,7 @@
 
  private:
   rtc::ThreadChecker construction_thread_;
-  // Protect |_timestampMap|.
+  rtc::ThreadChecker decoder_thread_;
   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)
@@ -67,10 +70,9 @@
   // 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 RTC_GUARDED_BY(lock_);
-  uint64_t _lastReceivedPictureID;
+  VCMTiming* _timing RTC_GUARDED_BY(decoder_thread_);
+  VCMTimestampMap _timestampMap RTC_GUARDED_BY(decoder_thread_);
+  uint64_t _lastReceivedPictureID RTC_GUARDED_BY(decoder_thread_);
   int64_t ntp_offset_;
 };
 
@@ -97,22 +99,24 @@
   */
   int32_t RegisterDecodeCompleteCallback(VCMDecodedFrameCallback* callback);
 
-  bool External() const;
   bool PrefersLateDecoding() const;
   bool IsSameDecoder(VideoDecoder* decoder) const {
     return decoder_.get() == decoder;
   }
 
  private:
-  VCMDecodedFrameCallback* _callback;
-  VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength];
-  uint32_t _nextFrameInfoIdx;
+  rtc::ThreadChecker decoder_thread_;
+  VCMDecodedFrameCallback* _callback RTC_GUARDED_BY(decoder_thread_);
+  VCMFrameInformation _frameInfos[kDecoderFrameMemoryLength] RTC_GUARDED_BY(
+      decoder_thread_);
+  uint32_t _nextFrameInfoIdx RTC_GUARDED_BY(decoder_thread_);
   std::unique_ptr<VideoDecoder> decoder_;
-  VideoCodecType _codecType;
+  VideoCodecType _codecType RTC_GUARDED_BY(decoder_thread_);
   const bool _isExternal;
   VideoContentType _last_keyframe_content_type;
 };
 
 }  // namespace webrtc
 
+#endif  // defined(WEBRTC_ANDROID)
 #endif  // MODULES_VIDEO_CODING_GENERIC_DECODER_H_