Mp4RtpHintInfo.cpp
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:5k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*****************************************************************
  2. |
  3. |    AP4 - MP4 Rtp Hint Info
  4. |
  5. |    Copyright 2002-2005 Gilles Boccon-Gibod & Julien Boeuf
  6. |
  7. |
  8. |    This file is part of Bento4/AP4 (MP4 Atom Processing Library).
  9. |
  10. |    Unless you have obtained Bento4 under a difference license,
  11. |    this version of Bento4 is Bento4|GPL.
  12. |    Bento4|GPL is free software; you can redistribute it and/or modify
  13. |    it under the terms of the GNU General Public License as published by
  14. |    the Free Software Foundation; either version 2, or (at your option)
  15. |    any later version.
  16. |
  17. |    Bento4|GPL is distributed in the hope that it will be useful,
  18. |    but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. |    GNU General Public License for more details.
  21. |
  22. |    You should have received a copy of the GNU General Public License
  23. |    along with Bento4|GPL; see the file COPYING.  If not, write to the
  24. |    Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
  25. |    02111-1307, USA.
  26. |
  27. ****************************************************************/
  28. /*----------------------------------------------------------------------
  29. |       includes
  30. +---------------------------------------------------------------------*/
  31. #include <stdio.h>
  32. #include <stdlib.h>
  33. #include "Ap4.h"
  34. #include "Ap4HintTrackReader.h"
  35. #include "Ap4ByteStream.h"
  36. #include "Ap4File.h"
  37. #include "Ap4Movie.h"
  38. #include "Ap4FileByteStream.h"
  39. /*----------------------------------------------------------------------
  40. |       constants
  41. +---------------------------------------------------------------------*/
  42. #define BANNER "MP4 Rtp Hint Info - Version 0.1an"
  43.     "(c) 2002-2005 Gilles Boccon-Gibod & Julien Boeuf"
  44. /*----------------------------------------------------------------------
  45. |       PrintUsageAndExit
  46. +---------------------------------------------------------------------*/
  47. static void
  48. PrintUsageAndExit()
  49. {
  50.     fprintf(stderr, 
  51.         BANNER 
  52.         "nnusage: mp4rtphintinfo [options] <input>n");
  53.     exit(1);
  54. }
  55. /*----------------------------------------------------------------------
  56. |       DumpRtpPackets
  57. +---------------------------------------------------------------------*/
  58. static AP4_Result
  59. DumpRtpPackets(AP4_HintTrackReader& reader, const char* file_name)
  60. {
  61.     // create the output stream
  62.     AP4_ByteStream* output;
  63.     try {
  64.         output = new AP4_FileByteStream(file_name,
  65.             AP4_FileByteStream::STREAM_MODE_WRITE);
  66.     } catch (AP4_Exception) {
  67.         fprintf(stderr, "ERROR: cannot open output file (%s)n", file_name);
  68.         return AP4_FAILURE;
  69.     }
  70.     // read the packets from the reader and write them in the output stream
  71.     AP4_DataBuffer data(1500);
  72.     AP4_TimeStamp ts;
  73.     while(AP4_SUCCEEDED(reader.GetNextPacket(data, ts))) {
  74.         output->Write(data.GetData(), data.GetDataSize());
  75.         AP4_Debug("#########ntpacket contains %d bytesn", data.GetDataSize());
  76.         AP4_Debug("tsent at time stamp %dnn", ts);
  77.     }
  78.     
  79.     output->Release();
  80.     return AP4_SUCCESS;
  81. }
  82. /*----------------------------------------------------------------------
  83. |       main
  84. +---------------------------------------------------------------------*/
  85. int
  86. main(int argc, char** argv)
  87. {
  88.     AP4_Result result = AP4_SUCCESS;
  89.     // parse the command line
  90.     if (argc != 2) PrintUsageAndExit();
  91.     // create the input stream
  92.     AP4_ByteStream* input;
  93.     try {
  94.         input = new AP4_FileByteStream(argv[1],
  95.             AP4_FileByteStream::STREAM_MODE_READ);
  96.     } catch (AP4_Exception) {
  97.         fprintf(stderr, "ERROR: cannot open input file (%s)n", argv[1]);
  98.         return 1;
  99.     }
  100.     AP4_File* file = new AP4_File(*input);
  101.   
  102.     AP4_Movie* movie = file->GetMovie();
  103.     if (movie != NULL) {
  104.         // get a hint track reader
  105.         AP4_Track* hint_track = movie->GetTrack(AP4_Track::TYPE_HINT, 1);
  106.         if (hint_track == NULL) {
  107.             AP4_Debug("No hint track in this movien");
  108.             return AP4_FAILURE;
  109.         }
  110.         AP4_HintTrackReader reader(*hint_track, *movie, 0x01020304);
  111.         AP4_String rtp_file_name(argv[1]);
  112.         rtp_file_name += ".rtp";
  113.         // display the sdp
  114.         AP4_String sdp;
  115.         reader.GetSdpText(sdp);
  116.         AP4_Debug("sdp:n%snn", sdp.c_str());
  117.         // dump the packet
  118.         result = DumpRtpPackets(reader, rtp_file_name.c_str());
  119.         if (AP4_FAILED(result)) goto bail;
  120.     } else {
  121.         AP4_Debug("No movie found in the filen");
  122.         return AP4_FAILURE;
  123.     }
  124. bail:
  125.     delete file;
  126.     input->Release();
  127.     return result;
  128. }