FramedSource.hh 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /**********
  2. This library is free software; you can redistribute it and/or modify it under
  3. the terms of the GNU Lesser General Public License as published by the
  4. Free Software Foundation; either version 3 of the License, or (at your
  5. option) any later version. (See <http://www.gnu.org/copyleft/lesser.html>.)
  6. This library is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
  9. more details.
  10. You should have received a copy of the GNU Lesser General Public License
  11. along with this library; if not, write to the Free Software Foundation, Inc.,
  12. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  13. **********/
  14. // "liveMedia"
  15. // Copyright (c) 1996-2019 Live Networks, Inc. All rights reserved.
  16. // Framed Sources
  17. // C++ header
  18. #ifndef _FRAMED_SOURCE_HH
  19. #define _FRAMED_SOURCE_HH
  20. #ifndef _NET_COMMON_H
  21. #include "NetCommon.h"
  22. #endif
  23. #ifndef _MEDIA_SOURCE_HH
  24. #include "MediaSource.hh"
  25. #endif
  26. class FramedSource: public MediaSource {
  27. public:
  28. static Boolean lookupByName(UsageEnvironment& env, char const* sourceName,
  29. FramedSource*& resultSource);
  30. typedef void (afterGettingFunc)(void* clientData, unsigned frameSize,
  31. unsigned numTruncatedBytes,
  32. struct timeval presentationTime,
  33. unsigned durationInMicroseconds);
  34. typedef void (onCloseFunc)(void* clientData);
  35. void getNextFrame(unsigned char* to, unsigned maxSize,
  36. afterGettingFunc* afterGettingFunc,
  37. void* afterGettingClientData,
  38. onCloseFunc* onCloseFunc,
  39. void* onCloseClientData);
  40. static void handleClosure(void* clientData);
  41. void handleClosure();
  42. // This should be called (on ourself) if the source is discovered
  43. // to be closed (i.e., no longer readable)
  44. void stopGettingFrames();
  45. virtual unsigned maxFrameSize() const;
  46. // size of the largest possible frame that we may serve, or 0
  47. // if no such maximum is known (default)
  48. virtual void doGetNextFrame() = 0;
  49. // called by getNextFrame()
  50. Boolean isCurrentlyAwaitingData() const {return fIsCurrentlyAwaitingData;}
  51. static void afterGetting(FramedSource* source);
  52. // doGetNextFrame() should arrange for this to be called after the
  53. // frame has been read (*iff* it is read successfully)
  54. protected:
  55. FramedSource(UsageEnvironment& env); // abstract base class
  56. virtual ~FramedSource();
  57. virtual void doStopGettingFrames();
  58. protected:
  59. // The following variables are typically accessed/set by doGetNextFrame()
  60. unsigned char* fTo; // in
  61. unsigned fMaxSize; // in
  62. unsigned fFrameSize; // out
  63. unsigned fNumTruncatedBytes; // out
  64. struct timeval fPresentationTime; // out
  65. unsigned fDurationInMicroseconds; // out
  66. private:
  67. // redefined virtual functions:
  68. virtual Boolean isFramedSource() const;
  69. private:
  70. afterGettingFunc* fAfterGettingFunc;
  71. void* fAfterGettingClientData;
  72. onCloseFunc* fOnCloseFunc;
  73. void* fOnCloseClientData;
  74. Boolean fIsCurrentlyAwaitingData;
  75. };
  76. #endif