Example #1
0
/**
 * @brief Creates a mission OSD.
 *
 * @note You can index elements by using '\t' as first character of an element.
 *
 * @usage misn.osdCreate( "My OSD", {"Element 1", "Element 2"})
 *
 *    @luaparam title Title to give the OSD.
 *    @luaparam list List of elements to put in the OSD.
 * @luafunc osdCreate( title, list )
 */
static int misn_osdCreate( lua_State *L )
{
   const char *title;
   int nitems;
   char **items;
   int i;
   Mission *cur_mission;

   cur_mission = misn_getFromLua(L);

   /* Must be accepted. */
   if (!cur_mission->accepted) {
      WARN("Can't create an OSD on an unaccepted mission!");
      return 0;
   }

   /* Check parameters. */
   title  = luaL_checkstring(L,1);
   luaL_checktype(L,2,LUA_TTABLE);
   nitems = lua_objlen(L,2);

   /* Destroy OSD if already exists. */
   if (cur_mission->osd != 0) {
      osd_destroy( cur_mission->osd );
      cur_mission->osd = 0;
   }

   /* Allocate items. */
   items = calloc( nitems, sizeof(char *) );

   /* Get items. */
   for (i=0; i<nitems; i++) {
      lua_pushnumber(L,i+1);
      lua_gettable(L,2);
      if (!lua_isstring(L,-1)) {
         free(items);
         luaL_typerror(L, -1, "string");
         return 0;
      }
      items[i] = strdup( lua_tostring(L, -1) );
      lua_pop(L,1);
   }

   /* Create OSD. */
   cur_mission->osd = osd_create( title, nitems, (const char**) items,
         cur_mission->data->avail.priority );
   cur_mission->osd_set = 1; /* OSD was explicitly set. */

   /* Free items. */
   for (i=0; i<nitems; i++)
      free(items[i]);
   free(items);

   return 0;
}
Example #2
0
/*
 recursive generation of the OSD contexts
 called after static menu tree creation and whenever a filesystem
 menu is created
 if each menu's OSD was built in the animenu_createmenu() call
 the order of generation would be from leaf to root, so the parent
 geometry wouldn't be available
*/
int animenu_genosd(struct animenucontext *menu) {
  int result = TRUE;
  struct animenuitem *item;
  struct osdcontext *parent = NULL;
  if (menu->parent)
    parent = menu->parent->osd;
  if (!(menu->osd = osd_create(parent, animenu_idcallback, menu->firstitem)))
    return(FALSE);
  item = menu->firstitem;
  while (item) {
    if (item->type == animenuitem_menu) {
      result &= animenu_genosd(item->menu);
    }
    item = item->next;
   }
  return(result);
}
Example #3
0
/**
 * @brief Parses the actual individual mission nodes.
 *
 *    @param parent Parent node to parse.
 *    @return 0 on success.
 */
static int missions_parseActive( xmlNodePtr parent )
{
   Mission *misn;
   MissionData *data;
   int m, i;
   char *buf;
   char *title;
   const char **items;
   int nitems;
   int id, sys, type;
   StarSystem *ssys;

   xmlNodePtr node, cur, nest;

   m = 0; /* start with mission 0 */
   node = parent->xmlChildrenNode;
   do {
      if (xml_isNode(node,"mission")) {
         misn = player_missions[m];

         /* process the attributes to create the mission */
         xmlr_attr(node,"data",buf);
         data = mission_get(mission_getID(buf));
         if (data == NULL) {
            WARN("Mission '%s' from savegame not found in game - ignoring.", buf);
            free(buf);
            continue;
         }
         else {
            if (mission_init( misn, data, 0, 0, NULL )) {
               WARN("Mission '%s' from savegame failed to load properly - ignoring.", buf);
               free(buf);
               continue;
            }
            misn->accepted = 1;
         }
         free(buf);

         /* this will orphan an identifier */
         xmlr_attr(node,"id",buf);
         misn->id = atol(buf);
         free(buf);

         cur = node->xmlChildrenNode;
         do {

            xmlr_strd(cur,"title",misn->title);
            xmlr_strd(cur,"desc",misn->desc);
            xmlr_strd(cur,"reward",misn->reward);

            /* Get the markers. */
            if (xml_isNode(cur,"markers")) {
               nest = cur->xmlChildrenNode;
               do {
                  if (xml_isNode(nest,"marker")) {
                     /* Get ID. */
                     xmlr_attr(nest,"id",buf);
                     id = (buf != NULL) ? atoi(buf) : -1;
                     if (buf != NULL)
                        free(buf);
                     /* Get type. */
                     xmlr_attr(nest,"type",buf);
                     type = (buf != NULL) ? atoi(buf) : -1;
                     if (buf != NULL)
                        free(buf);
                     /* Get system. */
                     ssys = system_get( xml_get( nest ));
                     if (ssys == NULL) {
                        WARN( "System Marker to '%s' does not exist", xml_get( nest ) );
                        continue;
                     }
                     sys = system_index( ssys );
                     mission_addMarker( misn, id, sys, type );
                  }
               } while (xml_nextNode(nest));
            }

            /* Cargo. */
            if (xml_isNode(cur,"cargos")) {
               nest = cur->xmlChildrenNode;
               do {
                  if (xml_isNode(nest,"cargo"))
                     mission_linkCargo( misn, xml_getLong(nest) );
               } while (xml_nextNode(nest));
            }

            /* OSD. */
            if (xml_isNode(cur,"osd")) {
               xmlr_attr(cur,"nitems",buf);
               if (buf != NULL) {
                  nitems = atoi(buf);
                  free(buf);
               }
               else
                  continue;
               xmlr_attr(cur,"title",title);
               items = malloc( nitems * sizeof(char*) );
               i = 0;
               nest = cur->xmlChildrenNode;
               do {
                  if (xml_isNode(nest,"msg")) {
                     if (i > nitems) {
                        WARN("Inconsistency with 'nitems' in savefile.");
                        break;
                     }
                     items[i] = xml_get(nest);
                     i++;
                  }
               } while (xml_nextNode(nest));

               /* Create the osd. */
               misn->osd = osd_create( title, nitems, items, data->avail.priority );
               free(items);
               free(title);

               /* Set active. */
               xmlr_attr(cur,"active",buf);
               if (buf != NULL) {
                  osd_active( misn->osd, atoi(buf) );
                  free(buf);
               }
            }

            /* Claims. */
            if (xml_isNode(cur,"claims"))
               misn->claims = claim_xmlLoad( cur );

            if (xml_isNode(cur,"lua"))
               /* start the unpersist routine */
               nxml_unpersistLua( misn->L, cur );

         } while (xml_nextNode(cur));



         m++; /* next mission */
         if (m >= MISSION_MAX) break; /* full of missions, must be an error */
      }
   } while (xml_nextNode(node));

   return 0;
}
/*****************************************************************************
 Prototype    : vid_enc_thr_init
 Description  : Init thread
 Input        : VidEncThrArg *arg   
                VidEncThrEnv *envp  
 Output       : None
 Return Value : static
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2012/3/8
    Author       : Sun
    Modification : Created function

*****************************************************************************/
static Int32 vid_enc_thr_init(VidEncThrArg *arg, VidEncThrEnv *envp)
{
	Int32 err;
	
	assert(arg && arg->hParamsMng && arg->hDispatch);

	/* clear */
	memset(envp, 0, sizeof(VidEncThrEnv));
	envp->hParamsMng = arg->hParamsMng;
	envp->hDispatch = arg->hDispatch;

	/* no longer need input arg */
	free(arg);

	/* init jpeg encode params */
	H264EncInitParams	encInitParams;
	H264EncDynParams	encDynParams;

	encInitParams = H264ENC_INIT_DEFAULT;

	/* get dyn params, we may need wait capture ready */
	err = params_mng_control(envp->hParamsMng, PMCMD_G_H264ENCDYN, 
			&encDynParams, sizeof(encDynParams));
	if(err) {
		ERR("get h264 enc dyn params failed.");
		return err;
	}

	/* create h.264 enc handle */
	envp->hH264Enc = h264_enc_create(&encInitParams, &encDynParams);
	if(!envp->hH264Enc) {
		ERR("create h264 enc handle failed");
		return E_INVAL;
	}

	/* create osd handle */
	OsdInitParams	osdInitParams;
	OsdDynParams	osdDynParams;

	osdInitParams.size = sizeof(osdInitParams);
	osdInitParams.asc16Tab = NULL;
	osdInitParams.hzk16Tab = NULL;

	err = params_mng_control(envp->hParamsMng, PMCMD_G_VIDOSDDYN, 
			&osdDynParams, sizeof(osdDynParams));
	if(err) {
		ERR("get osd enc params failed.");
		return err;
	}	
	
	envp->hOsd = osd_create(&osdInitParams, &osdDynParams);
	if(!envp->hOsd) {
		ERR("create osd handle failed");
		return E_INVAL;
	}

	/* get current osd config */
	err = params_mng_control(envp->hParamsMng, PMCMD_G_OSDPARAMS, 
				&envp->osdCfg, sizeof(CamOsdParams));
	assert(err == E_NO);

	/* create msg handle  */
	envp->hMsg = msg_create(MSG_VID_ENC, MSG_IMG_TX, 0);
	if(!envp->hMsg) {
		ERR("create msg handle failed");
		return E_NOMEM;
	}

	/* alloc one buffer for encode */
	Uint32 bufSize = encInitParams.maxWidth * encInitParams.maxHeight * 8 / 10;
	bufSize = ROUND_UP(bufSize, 256);
	
	envp->hBufEnc = buffer_alloc(bufSize, NULL);
	if(!envp->hBufEnc) {
		ERR("alloc buf for enc failed");
		return E_NOMEM;
	}

	envp->exit = FALSE;

	DBG("vid enc thread init ok.");
	return E_NO;
}
Example #5
0
/*****************************************************************************
 Prototype    : img_enc_thr_init
 Description  : Init thread
 Input        : ImgEncThrArg *arg   
                EncoderHandle hEnc  
 Output       : None
 Return Value : static
 Calls        : 
 Called By    : 
 
  History        :
  1.Date         : 2012/3/8
    Author       : Sun
    Modification : Created function

*****************************************************************************/
static Int32 encoder_init(EncoderHandle hEnc, EncoderAttrs *attrs, EncoderParams *params)
{	
	assert(attrs && params && attrs->encFxns && attrs->encInitParams);

	hEnc->name = attrs->name;

	/* set params input */
	hEnc->saveRootPath = attrs->saveRootPath;
	hEnc->ops = attrs->encOps;
	hEnc->mutex = attrs->mutex;

	assert(hEnc->ops && hEnc->mutex);

	/* create enc handle */
	hEnc->hEncode = alg_create(attrs->encFxns, attrs->encInitParams, params->encDynBuf);
	if(!hEnc->hEncode) {
		ERR("<%s> create enc handle failed", hEnc->name);
		return E_INVAL;
	}

	/* create osd handle */
	OsdInitParams	osdInitParams;

	osdInitParams.size = sizeof(osdInitParams);
	osdInitParams.asc16Tab = NULL;
	osdInitParams.hzk16Tab = NULL;

	hEnc->hOsd = osd_create(&osdInitParams, &params->osdDyn);
	if(!hEnc->hOsd) {
		ERR("<%s> create osd handle failed", hEnc->name);
		return E_INVAL;
	}

	/* record current osd config */
	hEnc->osdInfo = params->osdInfo;

	/* create msg handle  */
	hEnc->hMsg = msg_create(attrs->msgName, attrs->dstName, 0);
	if(!hEnc->hMsg) {
		ERR("<%s> create msg handle failed", hEnc->name);
		return E_NOMEM;
	}

	/* create buffer pool for encoded image */
	Uint32 bufSize = attrs->encBufSize;
	bufSize = ROUND_UP(bufSize, 256);
	
	BufAllocAttrs	allocAttrs;
	allocAttrs.align = 256;
	allocAttrs.flags = 0;
	allocAttrs.type = BUF_TYPE_POOL;
	
	if(attrs->poolBufNum > 0) {
		hEnc->hPoolEnc = buf_pool_create(bufSize, attrs->poolBufNum, &allocAttrs);
		if(!hEnc->hPoolEnc) {
			ERR("<%s> create enc pool failed", hEnc->name);
			return E_NOMEM;
		}
	}

	/* alloc one buffer for save to local */
	hEnc->hBufEnc = buffer_alloc(bufSize, &allocAttrs);
	if(!hEnc->hBufEnc) {
		ERR("<%s> alloc buf for enc failed", hEnc->name);
		return E_NOMEM;
	}

	hEnc->exit = FALSE;

	return E_NO;
}