diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-20 23:53:49 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-20 23:53:49 +0000 |
commit | aacbaac07bef57ef5ae79c2bb73cc493697523a3 (patch) | |
tree | 9b3b167c132d69268133c9a7cf845b2808e3b693 /remoting/protocol/buffered_socket_writer.h | |
parent | 2d39c51b903086f01adf5470ee6725ced14df8ee (diff) | |
download | chromium_src-aacbaac07bef57ef5ae79c2bb73cc493697523a3.zip chromium_src-aacbaac07bef57ef5ae79c2bb73cc493697523a3.tar.gz chromium_src-aacbaac07bef57ef5ae79c2bb73cc493697523a3.tar.bz2 |
Simple RTP reader/writer.
This is an implementation of simple RTP reader and writer. It still lacks proper support of VP8 payload header. Will implement it in another CL.
BUG=None
TEST=None
Review URL: http://codereview.chromium.org/3829007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63294 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/protocol/buffered_socket_writer.h')
-rw-r--r-- | remoting/protocol/buffered_socket_writer.h | 66 |
1 files changed, 53 insertions, 13 deletions
diff --git a/remoting/protocol/buffered_socket_writer.h b/remoting/protocol/buffered_socket_writer.h index 3d4709d..dd1cde8 100644 --- a/remoting/protocol/buffered_socket_writer.h +++ b/remoting/protocol/buffered_socket_writer.h @@ -5,7 +5,7 @@ #ifndef REMOTING_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ #define REMOTING_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ -#include <deque> +#include <queue> #include "base/lock.h" #include "base/ref_counted.h" @@ -20,13 +20,22 @@ class Socket; namespace remoting { -class BufferedSocketWriter - : public base::RefCountedThreadSafe<BufferedSocketWriter> { +// BufferedSocketWriter and BufferedDatagramWriter implement write data queue +// for stream and datagram sockets. BufferedSocketWriterBase is a base class +// that implements base functionality common for streams and datagrams. +// These classes are particularly useful when data comes from a thread +// that doesn't own the socket, as Write() can be called from any thread. +// Whenever new data is written it is just put in the queue, and then written +// on the thread that owns the socket. GetBufferChunks() and GetBufferSize() +// can be used to throttle writes. + +class BufferedSocketWriterBase + : public base::RefCountedThreadSafe<BufferedSocketWriterBase> { public: typedef Callback1<int>::Type WriteFailedCallback; - BufferedSocketWriter(); - virtual ~BufferedSocketWriter(); + explicit BufferedSocketWriterBase(); + virtual ~BufferedSocketWriterBase(); // Initializes the writer. Must be called on the thread that will be used // to access the socket in the future. |callback| will be called after each @@ -47,28 +56,59 @@ class BufferedSocketWriter // Stops writing and drops current buffers. void Close(); - private: - typedef std::deque<scoped_refptr<net::IOBufferWithSize> > DataQueue; + protected: + typedef std::queue<scoped_refptr<net::IOBufferWithSize> > DataQueue; + + DataQueue queue_; + int buffer_size_; + + // Following two methods must be implemented in child classes. + // GetNextPacket() returns next packet that needs to be written to the + // socket. |buffer| must be set to NULL if there is nothing left in the queue. + virtual void GetNextPacket_Locked(net::IOBuffer** buffer, int* size) = 0; + virtual void AdvanceBufferPosition_Locked(int written) = 0; + private: void DoWrite(); void OnWritten(int result); + // Must be locked when accessing |socket_|, |queue_| and |buffer_size_|; + Lock lock_; + net::Socket* socket_; MessageLoop* message_loop_; scoped_ptr<WriteFailedCallback> write_failed_callback_; - Lock lock_; - - DataQueue queue_; - int buffer_size_; - scoped_refptr<net::DrainableIOBuffer> current_buf_; bool write_pending_; - net::CompletionCallbackImpl<BufferedSocketWriter> written_callback_; + net::CompletionCallbackImpl<BufferedSocketWriterBase> written_callback_; bool closed_; }; +class BufferedSocketWriter : public BufferedSocketWriterBase { + public: + BufferedSocketWriter(); + virtual ~BufferedSocketWriter(); + + protected: + virtual void GetNextPacket_Locked(net::IOBuffer** buffer, int* size); + virtual void AdvanceBufferPosition_Locked(int written); + + private: + scoped_refptr<net::DrainableIOBuffer> current_buf_; +}; + +class BufferedDatagramWriter : public BufferedSocketWriterBase { + public: + BufferedDatagramWriter(); + virtual ~BufferedDatagramWriter(); + + protected: + virtual void GetNextPacket_Locked(net::IOBuffer** buffer, int* size); + virtual void AdvanceBufferPosition_Locked(int written); +}; + } // namespace remoting #endif // REMOTING_PROTOCOL_BUFFERED_SOCKET_WRITER_H_ |