tci1.c
上传用户:chenpengke
上传日期:2018-03-28
资源大小:44995k
文件大小:15k
源码类别:

其他

开发平台:

C/C++

  1. /******************************************************************************
  2.  * File Name    : tci.c
  3.  *
  4.  * Description  :
  5.  *
  6.  * Author : Marino Congiu, Alessandro Innocenti - Dec 1999
  7.  *
  8.  * (c) Copyright STMicroelectronics - 1999
  9. ******************************************************************************/
  10. #define INFO_REPORTING 1
  11.  
  12. #include <stdio.h>
  13. #include <stddef.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <time.h>
  17. #include <debug.h>
  18. #include <stddefs.h>
  19. #include <stlite.h>
  20. #include <stevt.h>
  21. #include <stsubt.h>
  22. #include <common.h>
  23. #include <apdu.h>
  24. #include <setup.h>
  25. #define GLOBAL_DATA
  26. #include "app_data.h"
  27. #define NUMTC                 5
  28. #define VIDEO_PID             0   /* No Video stream   */
  29. #define AUDIO_PID             0   /* No Audio stream   */
  30. #define PCR_PID               0   /* No Sincronization */
  31. #define GET_MESSAGE_DELAY     CLOCKS_PER_SEC / 10
  32. #define PAUSE_BASE            CLOCKS_PER_SEC / 10
  33. #define CACHE_SIZE            (20 * 1024)
  34. #ifdef RDE_DISPLAY_SERVICE
  35. #define USING_RDE_DISPLAY     1
  36. #else
  37. #define USING_OSD_DISPLAY     1
  38. #endif
  39.  
  40. #ifdef USING_OSD_DISPLAY
  41.   #define DISPLAY_SERVICE        STSUBT_OSD_DisplayService
  42.   #define DISPLAY_REPORT
  43.   #define NUM_LOOP               2
  44. #elif defined USING_RDE_DISPLAY
  45.   extern void STSUBT_TEST_Report (void);
  46.   #define DISPLAY_SERVICE        STSUBT_RDE_DisplayService
  47.   #define DISPLAY_REPORT         
  48.   #define NUM_LOOP               2
  49. #elif defined USING_TEST_DISPLAY
  50.   extern void STSUBT_TEST_Report (void);
  51.   #define DISPLAY_SERVICE        STSUBT_TEST_DisplayService
  52.   #define DISPLAY_REPORT         STSUBT_TEST_Report()
  53.   #define NUM_LOOP               2
  54. #else
  55.   #define DISPLAY_SERVICE        STSUBT_NULL_DisplayService
  56.   #define DISPLAY_REPORT
  57.   #define NUM_LOOP               2
  58. #endif
  59. #define exit_failure(tcnum)         
  60. {             
  61.    ERROR_MSG(("TC_%u: ^^^Failedn",tcnum));  
  62.    INFO_MSG(("============================================================="));
  63.    return(EXIT_FAILURE);   
  64. }
  65. /* ----------------------------------------------------------------------- */
  66. /* ------------------------ define subtitling demo ----------------------- */
  67. /* ----------------------------------------------------------------------- */
  68. int main (void)
  69. {
  70.   ST_DeviceName_t        DeviceName="SUBT0";
  71.   STSUBT_Handle_t        SubtHandle;
  72.   STSUBT_InitParams_t    InitParams;
  73.   STSUBT_OpenParams_t    OpenParams;
  74.   STSUBT_ShowParams_t    ShowParams;
  75.   STSUBT_TermParams_t    TermParams;
  76.   ST_ErrorCode_t         ST_ErrorCode;
  77.  
  78.   APDU_t                *APDU_List;
  79.   SegmentBuffer_t        SegmentBuffer;
  80.   U32                    NumAPDU = 0;
  81.   U32                    ContAPDU = 0;
  82.   U32                    ContLoop = 0;
  83.   U32                    SegmentMore = 0;
  84.   U32                    APDUPacketLength =0;
  85.   U32                    APDUPacketTag =0;
  86.   U8                     APDUReplyData[3] ;
  87.   STSUBT_CallingMode_t   CallingMode;
  88.   char                *TXTFileName[NUMTC];
  89.   char                *APDFileName[NUMTC];
  90.   char                *SEGFileName[NUMTC];
  91.   char                *TCName[NUMTC];
  92.   TXTFileName[0]="../../ci/tci1a.txt";
  93.   APDFileName[0]="../../ci/tci1a.apd";
  94.   SEGFileName[0]="../../ci/tci1.seg";
  95.   TXTFileName[1]="../../ci/tci1b.txt";
  96.   APDFileName[1]="../../ci/tci1b.apd";
  97.   SEGFileName[1]="../../ci/tci1.seg";
  98.   TXTFileName[2]="../../ci/tci1c.txt";
  99.   APDFileName[2]="../../ci/tci1c.apd";
  100.   SEGFileName[2]="../../ci/tci1.seg";
  101.   TXTFileName[3]="../../ci/tci1d.txt";
  102.   APDFileName[3]="../../ci/tci1d.apd";
  103.   SEGFileName[3]="../../ci/tci1.seg";
  104.   TXTFileName[4]="../../ci/insect.txt";
  105.   APDFileName[4]="../../ci/insect.apd";
  106.   SEGFileName[4]="../../ci/insect.seg";
  107.   TCName[0]="TC_01: Showing subtitles displays by using scene_end_mark()";
  108.   TCName[1]="TC_02: Deferring displays using scene_done_message() and scene_control()";
  109.   TCName[2]="TC_03: Pausing and resuming decoder using decoder_continue_flag";
  110.   TCName[3]="TC_04: Pausing and resuming decoder using decoder_pause() and decoder_resume()";
  111.   TCName[4]="TC_05: Showing stored displays using scene_control() APDUs";
  112.   TermParams.ForceTerminate = FALSE;
  113.   /* Init ST20 core */
  114.   if ( BOOT_Init() != ST_NO_ERROR)
  115.   {
  116.       return ( EXIT_FAILURE );
  117.   }
  118.   /* Init of required driver */
  119.   if ( STAPISupportDriverSetup() != ST_NO_ERROR)
  120.   {
  121.       return ( EXIT_FAILURE );
  122.   }
  123.   if (STAPISubscribeEvents (DeviceName)!= ST_NO_ERROR)
  124.   {
  125.       return ( EXIT_FAILURE );
  126.   }
  127.   strcpy(OpenParams.stevt_name, EVTDeviceName);
  128.   strcpy(OpenParams.stclkrv_name, CLKRVDeviceName);
  129.   /* Init of all driver */
  130.   if (STAPIDriverSetup() != 0)
  131.   {
  132.       FATAL_MSG(("Main: Failed hardware initialization!n"));
  133.       return(EXIT_FAILURE);
  134.   }
  135.   InitParams.MemoryPartition = SystemPartition;
  136.   InitParams.FullScreenDisplayEnabled = FALSE;
  137.   InitParams.CommonInterfaceEnabled = TRUE;
  138.   InitParams.ObjectCacheSize = CACHE_SIZE;
  139.   if ((ST_ErrorCode = STSUBT_Init(DeviceName, &InitParams)) != ST_NO_ERROR)
  140.   {
  141.       FATAL_MSG(("Main: error Initializing the drivern"));
  142.       exit_failure(0);
  143.   }
  144.   OpenParams.WorkingMode = STSUBT_OverlayMode;
  145.   if ((ST_ErrorCode = STSUBT_Open(DeviceName,
  146.                                   &OpenParams,&SubtHandle)) != ST_NO_ERROR)
  147.   {
  148.       FATAL_MSG(("Main: error Opening the drivern")); 
  149.       exit_failure(0);
  150.   }
  151.   if ((ST_ErrorCode = STSUBT_Start(SubtHandle)) !=ST_NO_ERROR)
  152.   {
  153.       FATAL_MSG(("Main: error Starting the drivern"));
  154.       exit_failure(0);
  155.   }
  156.  
  157.   ShowParams.DisplayServiceName = DISPLAY_SERVICE;
  158.   ShowParams.RDEBuffer_p    = Setup_RDEBuffer_p;
  159.   ShowParams.RDEBufferSize  = RDE_BUFFER_SIZE;
  160.   if ((ST_ErrorCode = STSUBT_OutStart(SubtHandle, ShowParams)) != ST_NO_ERROR)
  161.   {
  162.       FATAL_MSG(("Main: error Enabling Displayn"));
  163.       exit_failure(0);
  164.   }
  165.   for (ContLoop = 0 ; ContLoop < NUMTC; ContLoop++)
  166.   {
  167.   INFO_MSG(("============================================================="));
  168.   INFO_MSG((TCName[ContLoop]));
  169.   if ((NumAPDU =DecodeAPDUFile(TXTFileName[ContLoop],APDFileName[ContLoop]))==0)
  170.   {
  171.       ERROR_MSG(("ERROR Decoding TXT APDU File"));
  172.       exit_failure((ContLoop+1));
  173.   }
  174.   DEBUG_MSG(("** Main: ----- APDUFile Decoded  ------ **n"));
  175.   if ((NumAPDU = LoadAPDUFile(APDFileName[ContLoop], &APDU_List)) == 0)
  176.   {
  177.       ERROR_MSG(("ERROR Loading APDU File"));
  178.       exit_failure((ContLoop+1));
  179.   }
  180.   DEBUG_MSG(("** Main: ----- APDUFile Loaded  ------ **n"));
  181.   if (LoadSegmentFile(SEGFileName[ContLoop], &SegmentBuffer) == EXIT_FAILURE)
  182.   {
  183.       ERROR_MSG(("ERROR Loading Segment File"));
  184.       exit_failure((ContLoop+1));
  185.   }
  186.   DEBUG_MSG(("Segment Buffer Size = %d",SegmentBuffer.SegmentBufferLength));
  187.     for (ContAPDU = 0 ; ContAPDU < NumAPDU ; ContAPDU++)
  188.     {
  189.       APDUReplyData[0] = 0;
  190.       APDUReplyData[1] = 0;
  191.       APDUReplyData[2] = 0;
  192.       APDUPacketLength = 0;
  193.       APDUPacketTag = 0;
  194.       CallingMode = 0;
  195.       switch (APDU_List[ContAPDU].APDU_Tag)
  196.       {
  197.         case STSUBT_SUBTITLE_SEGMENT_LAST_TAG :
  198.         case STSUBT_SUBTITLE_DOWNLOAD_LAST_TAG :
  199.             if (SegmentMore == 0)
  200.             {
  201.                 PeekNextSegment (&SegmentBuffer);
  202.             }
  203.             if (STSUBT_InsertPacket(SubtHandle,
  204.                        APDU_List[ContAPDU].APDU_Tag,
  205.                        (SegmentBuffer.SegmentLength - SegmentMore),
  206.                        (U8*)(SegmentBuffer.PointerToSegment) + SegmentMore) !=
  207.                                                                    ST_NO_ERROR)
  208.             {
  209.               FATAL_MSG(("Main: error Inserting APDU Packetn"));
  210.               exit_failure((ContLoop+1));
  211.             }
  212.             SegmentMore = 0;
  213.             task_delay(APDU_List[ContAPDU].Pause * PAUSE_BASE);
  214.             break;
  215.         case STSUBT_SUBTITLE_SEGMENT_MORE_TAG :
  216.         case STSUBT_SUBTITLE_DOWNLOAD_MORE_TAG :
  217.             if (SegmentMore == 0)
  218.             {
  219.                 PeekNextSegment (&SegmentBuffer);
  220.             }
  221.             if (STSUBT_InsertPacket(SubtHandle,
  222.                         APDU_List[ContAPDU].APDU_Tag,
  223.                         APDU_List[ContAPDU].ObjectId,
  224.                         (U8*)(SegmentBuffer.PointerToSegment) + SegmentMore) !=
  225.                                                                    ST_NO_ERROR)
  226.             {
  227.               FATAL_MSG(("Main: error Inserting APDU Packetn"));
  228.               exit_failure((ContLoop+1));
  229.             }
  230.             SegmentMore += APDU_List[ContAPDU].ObjectId;
  231.             break;
  232.         case STSUBT_SCENE_END_MARK_TAG :
  233.         case STSUBT_SCENE_CONTROL_TAG :
  234.             if (STSUBT_InsertPacket(SubtHandle,
  235.                                     APDU_List[ContAPDU].APDU_Tag,
  236.                                     1,
  237.                                     &(APDU_List[ContAPDU].Data)) != ST_NO_ERROR)
  238.             {
  239.               FATAL_MSG(("Main: error Inserting APDU Packetn"));
  240.               exit_failure((ContLoop+1));
  241.             }
  242.             task_delay(APDU_List[ContAPDU].Pause * PAUSE_BASE);
  243.             break;
  244.         case STSUBT_FLUSH_DOWNLOAD_TAG :
  245.         case STSUBT_DECODER_PAUSE_TAG :
  246.         case STSUBT_DECODER_RESUME_TAG :
  247.             if (STSUBT_InsertPacket(SubtHandle,
  248.                                     APDU_List[ContAPDU].APDU_Tag,
  249.                                     0,
  250.                                     NULL) != ST_NO_ERROR)
  251.             {
  252.               FATAL_MSG(("Main: error Inserting APDU Packetn"));
  253.               exit_failure((ContLoop+1));
  254.             }
  255.             task_delay(APDU_List[ContAPDU].Pause * PAUSE_BASE);
  256.             break;
  257.         case STSUBT_DISPLAY_MESSAGE_TAG :
  258.             ST_ErrorCode = STSUBT_GetMessagePacket(SubtHandle,
  259.                                                    &APDUPacketTag,
  260.                                                    &APDUPacketLength,
  261.                                                    (void*)APDUReplyData);
  262.             while(ST_ErrorCode == STSUBT_ERROR_NO_PACKET_AVAILABLE) 
  263.             {
  264.               ST_ErrorCode = STSUBT_GetMessagePacket(SubtHandle,
  265.                                                      &APDUPacketTag,
  266.                                                      &APDUPacketLength,
  267.                                                      (void*)APDUReplyData);
  268.               task_delay(GET_MESSAGE_DELAY);
  269.             }
  270.             if (ST_ErrorCode != ST_NO_ERROR)
  271.             {
  272.               FATAL_MSG(("Main: Error Getting APDU Packetn"));
  273.               exit_failure((ContLoop+1));
  274.             }
  275.             if (APDUReplyData[0] != APDU_List[ContAPDU].Data)
  276.             {
  277.               ERROR_MSG(("ERROR: Wrong Error Expected = %x Returned = %x",
  278.                           APDU_List[ContAPDU].Data,
  279.                           APDUReplyData[0]));
  280.               exit_failure((ContLoop+1));
  281.             }
  282.             break;
  283.         case STSUBT_SCENE_DONE_MESSAGE_TAG :
  284.             CallingMode = STSUBT_Blocking;
  285.             ST_ErrorCode = STSUBT_GetReplyPacket(SubtHandle,
  286.                                                  &APDUPacketTag,
  287.                                                  &APDUPacketLength,
  288.                                                  (void*)APDUReplyData,
  289.                                                  CallingMode);
  290.             if (ST_ErrorCode != ST_NO_ERROR)
  291.             {
  292.               FATAL_MSG(("Main: Error Getting APDU Packetn"));
  293.               exit_failure((ContLoop+1));
  294.             }
  295.             if (APDUPacketTag != APDU_List[ContAPDU].APDU_Tag)
  296.             {
  297.               ERROR_MSG(("ERROR: Wrong Tag Expected = %x Returned = %x",
  298.                           APDU_List[ContAPDU].APDU_Tag,
  299.                           APDUPacketTag));
  300.               exit_failure((ContLoop+1));
  301.             }
  302.             if (APDUPacketLength != 1)
  303.             {
  304.               ERROR_MSG(("ERROR: Wrong Length Expected = %d Returned = %d",
  305.                          1,APDUPacketLength));
  306.               exit_failure((ContLoop+1));
  307.             }
  308.             if (APDUReplyData[0] != APDU_List[ContAPDU].Data)
  309.             {
  310.               ERROR_MSG(("ERROR: Wrong Data Expected = %x Returned = %x",
  311.                           APDU_List[ContAPDU].Data,
  312.                           APDUReplyData[0]));
  313.               exit_failure((ContLoop+1));
  314.             }
  315.             break;
  316.         case STSUBT_DOWNLOAD_REPLY_TAG :
  317.             CallingMode = STSUBT_Blocking;
  318.             ST_ErrorCode = STSUBT_GetReplyPacket(SubtHandle,
  319.                                                  &APDUPacketTag,
  320.                                                  &APDUPacketLength,
  321.                                                  (void*)APDUReplyData,
  322.                                                  CallingMode);
  323.             if (ST_ErrorCode != ST_NO_ERROR)
  324.             {
  325.               FATAL_MSG(("Main: Error Getting APDU Packetn"));
  326.               exit_failure((ContLoop+1));
  327.             }
  328.             if (APDUPacketTag != APDU_List[ContAPDU].APDU_Tag)
  329.             {
  330.               ERROR_MSG(("ERROR: Wrong Tag Expected = %x Returned = %x",
  331.                           APDU_List[ContAPDU].APDU_Tag,
  332.                           APDUPacketTag));
  333.               exit_failure((ContLoop+1));
  334.             }
  335.             if (APDUPacketLength != 3)
  336.             {
  337.               ERROR_MSG(("ERROR: Wrong Length Expected = %d Returned = %d",
  338.                          3,APDUPacketLength));
  339.               exit_failure((ContLoop+1));
  340.             }
  341.             if (APDUReplyData[2] != APDU_List[ContAPDU].Data)
  342.             {
  343.               ERROR_MSG(("ERROR: Wrong Data Expected = %x Returned = %x",
  344.                           APDU_List[ContAPDU].Data,
  345.                           APDUReplyData[2]));
  346.               exit_failure((ContLoop+1));
  347.             }
  348.             if ( ((APDUReplyData[0] << 8) + APDUReplyData[1]) !=
  349.                  APDU_List[ContAPDU].ObjectId)
  350.             {
  351.               ERROR_MSG(("ERROR: Wrong ObjectId Expected = %d Returned = %d",
  352.                          APDU_List[ContAPDU].ObjectId,
  353.                          ((APDUReplyData[0] << 8) + APDUReplyData[1]) ));
  354.               exit_failure((ContLoop+1));
  355.             }
  356.             break;
  357.         default :
  358.             ERROR_MSG(("Main: INVALID APDU TAG - APDU n = %d APDUTAG = %x",
  359.                          ContAPDU,
  360.                          APDU_List[ContAPDU].APDU_Tag));
  361.             exit_failure((ContLoop+1));
  362.             break;
  363.       }
  364.     }
  365.     FreeSegmentBuffer(&SegmentBuffer);
  366.     FreeAPDUList(&APDU_List);
  367.     INFO_MSG(("TC_0%d: ^^^Passed",(ContLoop+1)));
  368.   }
  369.   INFO_MSG(("============================================================="));
  370.   if ((ST_ErrorCode = STSUBT_Hide(SubtHandle)) != ST_NO_ERROR)
  371.   {
  372.       FATAL_MSG(("Main: error Disabling Displayn"));
  373.       exit_failure(1);
  374.   }
  375.   if ((ST_ErrorCode = STSUBT_Stop(SubtHandle)) != ST_NO_ERROR)
  376.   {
  377.       FATAL_MSG(("Main: error Stopping the drivern"));
  378.       exit_failure(1);
  379.   }
  380.   if ((ST_ErrorCode = STSUBT_Close(SubtHandle)) != ST_NO_ERROR)
  381.   {
  382.       FATAL_MSG(("Main: error Closing the drivern"));
  383.       exit_failure(1);
  384.   }
  385.   if ((ST_ErrorCode = STSUBT_Term(DeviceName,&TermParams)) != ST_NO_ERROR)
  386.   {
  387.       FATAL_MSG(("Main: error Terminating the drivern"));
  388.       exit_failure(1);
  389.   }
  390.   DISPLAY_REPORT;
  391.   STAPIDriverTerminate();
  392.   STAPIUnsubscribeEvents (DeviceName);
  393.   STAPISupportDriverTerminate();
  394.   /* --- terminate hardware system --- */
  395.  
  396.   return (EXIT_SUCCESS);
  397. }