change PacketBuffer to return it's result rather that use callback

Bug: None
Change-Id: I8cc05dd46e811d6db37af520d2106af21c671def
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/157893
Reviewed-by: Philip Eliasson <philipel@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29589}
diff --git a/modules/video_coding/packet_buffer.h b/modules/video_coding/packet_buffer.h
index c2a5e54..023cce2 100644
--- a/modules/video_coding/packet_buffer.h
+++ b/modules/video_coding/packet_buffer.h
@@ -16,43 +16,37 @@
 #include <set>
 #include <vector>
 
+#include "absl/base/attributes.h"
 #include "api/video/encoded_image.h"
+#include "modules/video_coding/frame_object.h"
 #include "modules/video_coding/packet.h"
 #include "rtc_base/critical_section.h"
 #include "rtc_base/numerics/sequence_number_util.h"
 #include "rtc_base/thread_annotations.h"
+#include "system_wrappers/include/clock.h"
 
 namespace webrtc {
-
-class Clock;
-
 namespace video_coding {
 
-class RtpFrameObject;
-
-// A frame is assembled when all of its packets have been received.
-class OnAssembledFrameCallback {
- public:
-  virtual ~OnAssembledFrameCallback() {}
-  virtual void OnAssembledFrame(std::unique_ptr<RtpFrameObject> frame) = 0;
-};
-
 class PacketBuffer {
  public:
+  struct InsertResult {
+    std::vector<std::unique_ptr<RtpFrameObject>> frames;
+    // Indicates if the packet buffer was cleared, which means that a key
+    // frame request should be sent.
+    bool buffer_cleared = false;
+  };
+
   // Both |start_buffer_size| and |max_buffer_size| must be a power of 2.
-  PacketBuffer(Clock* clock,
-               size_t start_buffer_size,
-               size_t max_buffer_size,
-               OnAssembledFrameCallback* frame_callback);
+  PacketBuffer(Clock* clock, size_t start_buffer_size, size_t max_buffer_size);
   ~PacketBuffer();
 
-  // Returns true unless the packet buffer is cleared, which means that a key
-  // frame request should be sent. The PacketBuffer will always take ownership
-  // of the |packet.dataPtr| when this function is called.
-  bool InsertPacket(VCMPacket* packet);
+  // The PacketBuffer will always take ownership of the |packet.dataPtr| when
+  // this function is called.
+  InsertResult InsertPacket(VCMPacket* packet) ABSL_MUST_USE_RESULT;
+  InsertResult InsertPadding(uint16_t seq_num) ABSL_MUST_USE_RESULT;
   void ClearTo(uint16_t seq_num);
   void Clear();
-  void PaddingReceived(uint16_t seq_num);
 
   // Timestamp (not RTP timestamp) of the last received packet/keyframe packet.
   absl::optional<int64_t> LastReceivedPacketMs() const;
@@ -132,10 +126,6 @@
   // determine continuity between them.
   std::vector<StoredPacket> buffer_ RTC_GUARDED_BY(crit_);
 
-  // Called when all packets in a frame are received, allowing the frame
-  // to be assembled.
-  OnAssembledFrameCallback* const assembled_frame_callback_;
-
   // Timestamp (not RTP timestamp) of the last received packet/keyframe packet.
   absl::optional<int64_t> last_received_packet_ms_ RTC_GUARDED_BY(crit_);
   absl::optional<int64_t> last_received_keyframe_packet_ms_